Here's some code that reads latitude and longitude info from the exif and, if locations are enabled for the image node type, sets it to do automatic geocoding of image nodes.
I didn't have time to make a patch and since the code is small, I'll post it directly. Put it in photobar_create_image between
$exif = exif_read_data($file);
if ( $exif && isset($exif['DateTime']) ) { ...
Here's the code:
$enable_locations = variable_get('location_image', 0);
if ($exif && $enable_locations && isset($exif['GPSLatitude'])) {
$latitude = $exif['GPSLatitude'][0] + $exif['GPSLatitude'][1]/60 + $exif['GPSLatitude'][2]/3600;
}
else {
$latitude = -1;
}
if ($exif && $enable_locations && isset($exif['GPSLongitude'])) {
$longitude = $exif['GPSLongitude'][0] + $exif['GPSLongitude'][1]/60 + $exif['GPSLongitude'][2]/3600;
}
else {
$longitude = -1;
}
if ($latitude != -1 && $longitude != -1) {
$node->location['latitude'] = $latitude;
$node->location['longitude'] = $longitude;
$node->location['lat'] = $latitude;
$node->location['lon'] = $longitude;
}
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | geolocate.patch | 1.78 KB | voidberg |
Comments
Comment #1
voidberg commentedThe code I posted before has some bugs, the locations are a little off the correct ones. Here's the correct code.
Comment #2
jakin commentedThanks, looks good and has been committed :-)