I would like to extract the GPS EXIF tag from pictures using php.
I'm using the exif_read_data()
that returns a array of all tags + data :
GPS.GPSLatitudeRef: N
GPS.GPSLatitude:Array ( [0] => 46/1 [1] => 5403/100 [2] => 0/1 )
GPS.GPSLongitudeRef: E
GPS.GPSLongitude:Array ( [0] => 7/1 [1] => 880/100 [2] => 0/1 )
GPS.GPSAltitudeRef:
GPS.GPSAltitude: 634/1
I don't know how to interpret 46/1 5403/100 and 0/1 ? 46 might be 46° but what about the rest especially 0/1 ?
angle/1 5403/100 0/1
What is this structure about ?
How to convert them to "standard" ones (like 46°56′48″N 7°26′39″E from wikipedia) ? I would like to pass thoses coordinates to the google maps api to display the pictures positions on a map !
This is a javascript port of the PHP-code posted @Gerald above. This way you can figure out the location of an image without ever uploading the image, in conjunction with libraries like dropzone.js and Javascript-Load-Image
short story. First part N Leave the grade multiply the minutes with 60 devide the seconds with 100. count the grades,minuts and seconds with eachother.
Second part E Leave the grade multiply the minutes with 60 devide the seconds with ...1000 cöunt the grades, minutes and seconds with each other
According to http://en.wikipedia.org/wiki/Geotagging,
( [0] => 46/1 [1] => 5403/100 [2] => 0/1 )
should mean 46/1 degrees, 5403/100 minutes, 0/1 seconds, i.e. 46°54.03′0″N. Normalizing the seconds gives 46°54′1.8″N.This code below should work, as long as you don't get negative coordinates (given that you get N/S and E/W as a separate coordinate, you shouldn't ever have negative coordinates). Let me know if there is a bug (I don't have a PHP environment handy at the moment).
With this GPS data:
Using the above code (thanks Gerald) I get these Latitude & Longitude values:
This is not correct. It's doing my head in as the code works, but the answer is wrong in this case! Many other images work fine, there just seems to be some logic missing to cater for something in this dat. For example, when I load the image in to iPhoto (sorry for the Apple example to those without Macs) it gets the answer right; this EXIF data is for a picture near the Red Sea.
The code I've used in the past is something like (in reality, it also checks that the data is vaguely valid):
Where you also have:
I know this question has been asked a long time ago, but I came across it while searching in google and the solutions proposed here did not worked for me. So, after further searching, here is what worked for me.
I'm putting it here so that anybody who comes here through some googling, can find different approaches to solve the same problem: