I am trying to convert the Exif longitude and latitude data into a Google friendly decimal value. I have read a lot of tutorials, but nothing seems to be working for me. I may well be doing this completely wrong.
I successfully get the Exif data as follows:
$exif_data = exif_read_data($path . '/user/images/4.jpg');
$egeoLong = $exif_data['GPSLongitude'];
$egeoLat = $exif_data['GPSLatitude'];
$egeoLongR = $exif_data['GPSLongitudeRef'];
$egeoLatR = $exif_data['GPSLatitudeRef'];
From there I end up with the following array for the values:
deg Long: 118/1
min Long: 2147/100
sec Long: 0/1
Longitude Ref: W
deg Lat: 34/1
min Lat: 433/100
sec Lat: 0/1
Latitude Ref: N
And I run them through this function to obtain a decimal value (I got this function here on Stackoverflow).
$geoLong = gpsDecimal($egeoLong[0], $egeoLong[1], $egeoLong[2], $egeoLongR);
$geoLat = gpsDecimal($egeoLat[0], $egeoLat[1], $egeoLat[2], $egeoLatR);
function gpsDecimal($deg, $min, $sec, $hemi) {
$d = $deg+((($min*60)+($sec))/3600);
return ($hemi=='S' || $hemi=='W') ? $d*=-1 : $d;
}
Which returns the following... that puts the coordinates in the middle of the ocean... not where I took the photo.
Latitude: 41.216666666667 Longitude: -153.78333333333
Can anyone tell me what I am doing wrong, or a better way to achieve this. Any help is much appreciated.