Sets Location module coordinates from GPS EXIF image data.
File
-
exif_location/
exif_location.module
View source
<?php
/**
* @file
* Sets Location module coordinates from GPS EXIF image data.
*/
/**
* Implements hook_node_presave().
*/
function exif_location_node_presave($node) {
// First check if EXIF lat and long fields exist.
if (is_array($node->field_gps_gpslatitude) && is_array($node->field_gps_gpslongitude)) {
$itemslat = field_get_items('node', $node, 'field_gps_gpslatitude');
$itemslong = field_get_items('node', $node, 'field_gps_gpslongitude');
// Then check if exif coordinates exist.
if (empty($itemslat) || empty($itemslong)) {
return;
}
$lat = field_view_value('node', $node, 'field_gps_gpslatitude', $itemslat[0]);
$lng = field_view_value('node', $node, 'field_gps_gpslongitude', $itemslong[0]);
// Then check if location coordinates are empty.
if (empty($node->location['latitude']) && empty($node->location['longitude'])) {
$node->locations = array(
array(
'locpick' => array(
'user_latitude' => $lat['#markup'],
'user_longitude' => $lng['#markup'],
),
),
);
drupal_set_message('Node location coordinates have been set from EXIF data', 'status');
}
}
}
/**
* Implements hook_form_alter().
*/
function exif_location_form_alter(&$form, $form_state, $form_id) {
// @todo Is this function still needed?
return;
// Remove the location element from the node form.
if (isset($form['#node']) && $form['#node']->type == 'image' && $form_id == $form['#node']->type . '_node_form') {
$form['locations']['#access'] = FALSE;
}
}
Functions
Title | Deprecated | Summary |
---|---|---|
exif_location_form_alter | Implements hook_form_alter(). | |
exif_location_node_presave | Implements hook_node_presave(). |