exif.inc in Geocoder 7
File
plugins/geocoder_handler/exif.inc
View source
<?php
$plugin = array(
'title' => t('Image/exif'),
'description' => t('Get a location from an image that was taken with a GPS enabled phone or camera'),
'callback' => 'geocoder_exif',
'field_types' => array(
'file',
'image',
),
'field_callback' => 'geocoder_exif_field',
);
function geocoder_exif($uri, $options = array()) {
foreach (module_implements('file_download') as $module) {
$function = $module . '_file_download';
$result = $function($uri);
if ($result === -1) {
throw new Exception(t('You do not have permission to access this file'));
}
}
geophp_load();
if ($data = exif_read_data(drupal_realpath($uri))) {
if (!isset($data['GPSLatitudeRef'])) {
return FALSE;
}
$lat = geocoder_exif_from($data['GPSLatitudeRef'], $data['GPSLatitude']);
$lon = geocoder_exif_from($data['GPSLongitudeRef'], $data['GPSLongitude']);
$point = new Point($lon, $lat);
return $point;
}
return FALSE;
}
function geocoder_exif_field($field, $field_item) {
if ($field_item['fid']) {
$file = file_load($field_item['fid']);
return geocoder_exif($file->uri);
}
}
function geocoder_exif_from($dir, $data) {
foreach ($data as $k => $item) {
list($deg, $pct) = explode('/', $item);
if ($pct) {
$data[$k] = $deg / $pct;
}
}
$point = (double) $data[0] + $data[1] / 60 + $data[2] / 3600;
if (in_array($dir, array(
'S',
'W',
), TRUE)) {
$point = $point * -1;
}
return $point;
}