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;
  }
CommentFileSizeAuthor
#1 geolocate.patch1.78 KBvoidberg

Comments

voidberg’s picture

StatusFileSize
new1.78 KB

The code I posted before has some bugs, the locations are a little off the correct ones. Here's the correct code.

jakin’s picture

Status: Needs review » Closed (fixed)

Thanks, looks good and has been committed :-)