How do I get the geo location data from an image using JavaScript / PHP?
I am开发者_Go百科 making a custom Google Maps application. I'd like to display all of my iPhone images on the map and I'd like to retrieve the geo location data using JavaScript or PHP. Is this possible? If not, what other way can I get the data?
Thanks.
Geo data using JavaScript answer:
The accepted answer only answers the PHP question, but if you are dealing with a smartphone photo there is a good chance the image is going to be 3megs or more! so getting EXIF data client side is what you want.
There is an awesome jQuery plugin which I have used. Download the project and open the index.html for a demo, uncomment line 26 //console.log(exifObject);
to see the object detail, you can get anything in the EXIF object, not just the Geodata:
http://plugins.jquery.com/file-exif/
In PHP, you can do this by using EXIF Functions
Its possible if the geo-location data is stored in the image metadata. You can do it with PHP using the Exif functions.
Once you parse the longitude and latitude from inside of the image meta data, use the Google Maps api to display it. There are a bunch of ways of embedding it depending on how interactive and styled you want the map:
http://code.google.com/apis/maps/index.html
If you just want a flat image use the static maps api. Keep in mind there's a lot of stuff you can set including zoom level. Example:
http://maps.google.com/maps/api/staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=14&size=512x512&maptype=roadmap&markers=color:blue|label:S|40.702147,-74.015794&markers=color:green|label:G|40.711614,-74.012318&markers=color:red|color:red|label:C|40.718217,-73.998284&sensor=false
This information is stored in the EXIF meta data in the image. In PHP you can read this data using the the exif_read_data()
function.
精彩评论