Get Image EXIF / Lat and Lng Position from images

[themify_is_logged_in]

[php]
/**
* get_image_location
* Returns an array of latitude and longitude from the Image file
* @param $image file path
* @return multitype:array|boolean
*/
function get_image_location($image = “){
$exif = exif_read_data($image, 0, true);
if($exif && isset($exif[‚GPS‘])){
$GPSLatitudeRef = $exif[‚GPS‘][‚GPSLatitudeRef‘];
$GPSLatitude = $exif[‚GPS‘][‚GPSLatitude‘];
$GPSLongitudeRef= $exif[‚GPS‘][‚GPSLongitudeRef‘];
$GPSLongitude = $exif[‚GPS‘][‚GPSLongitude‘];

$lat_degrees = count( $GPSLatitude ) > 0 ? gps2Num( $GPSLatitude[0] ) : 0;
$lat_minutes = count( $GPSLatitude ) > 1 ? gps2Num( $GPSLatitude[1] ) : 0;
$lat_seconds = count( $GPSLatitude ) > 2 ? gps2Num( $GPSLatitude[2] ) : 0;

$lon_degrees = count( $GPSLongitude ) > 0 ? gps2Num( $GPSLongitude[0] ) : 0;
$lon_minutes = count( $GPSLongitude ) > 1 ? gps2Num( $GPSLongitude[1] ) : 0;
$lon_seconds = count( $GPSLongitude ) > 2 ? gps2Num( $GPSLongitude[2] ) : 0;

$lat_direction = ( $GPSLatitudeRef == ‚W‘ or $GPSLatitudeRef == ‚S‘ ) ? -1 : 1;
$lon_direction = ( $GPSLongitudeRef == ‚W‘ or $GPSLongitudeRef == ‚S‘ ) ? -1 : 1;

$latitude = $lat_direction * ( $lat_degrees + ( $lat_minutes / 60 ) + ( $lat_seconds / ( 60*60 ) ) );
$longitude = $lon_direction * ( $lon_degrees + ( $lon_minutes / 60 ) + ( $lon_seconds / ( 60*60 ) ) );

return array( ‚latitude’=>$latitude, ‚longitude’=>$longitude );
}else{
return false;
}
}

function gps2Num( $coordPart ){
$parts = explode( ‚/‘, $coordPart );
if(count( $parts ) <= 0 )
return 0;
if( count( $parts ) == 1 )
return $parts[0];
return floatval( $parts[0] ) / floatval( $parts[1] );
}

function get_Image_EXIF( $post_id, $form_id ) {
if ( $form_id != 800 ) { // the WPUF Form ID
return;
}
if ( $post_id ) {
//get Image URL
$featured_img_url = get_the_post_thumbnail_url( $post_id );
//get location of image
$imgLocation = get_image_location( $featured_img_url );
//latitude & longitude
$imgLat = $imgLocation[‚latitude‘];
$imgLng = $imgLocation[‚longitude‘];
//Write image Lat/Lng
update_post_meta( $post_id, ‚your_meta_key_lat‘, $imgLat );
update_post_meta( $post_id, ‚your_meta_key_lng‘, $imgLng );
}
}
add_action( ‚wpuf_add_post_after_insert‘, ‚get_Image_EXIF‘, 10, 2 );
add_action( ‚wpuf_edit_post_after_update‘, ‚get_Image_EXIF‘, 10, 2 );[/php]

[/themify_is_logged_in]