I'm using the php exif_read_data
function to get the long and lat, then I'm converting them into a format the google can use, however they always seem to be a few miles out. The same country, just not the right position (iPhoto will give me the correct position, however). The code is as follows
public function get_location() {
global $the_image;
if(!empty($the_image)) {
$exif = $this->get_exif();
$degLong = $exif['GPSLongitude'][0];
$minLong = $exif['GPSLongitude'][1];
$secLong = $exif['GPSLongitude'][2];
$refLong = $exif['GPSLongitudeRef'];
$degLat = $exif['GPSLatitude'][0];
$minLat = $exif['GPSLatitude'][1];
$secLat = $exif['GPSLatitude'][2];
$refLat = $exif['GPSLatitudeRef'];
$long = $this->to_decimal($degLong, $minLong, $secLong, $refLong);
$lat = $this->to_decimal($degLat, $minLat, $secLat, $refLat);
echo $long . "<br />" . $lat . "<br/>";
} else {
echo "Supply an image";
}
}
function to_decimal($deg, $min, $sec, $hem){
$d = $deg + ((($min/60) + ($sec/3600))/100);
return ($hem =='S' || $hem=='W') ? $d*=-1 : $d;
}
Can anyone see what would make it return the wrong data, is my to_decimal
function wrong?
You devide the minutes and seconds by 100, but well, you shouldn't:
should be:
one minute is 1/60 degree and a second is 1/60 minute.
for a more thorough answer, see here: PHP extract GPS EXIF data