PHP and EXIF data for Google Maps mashup
I am trying to create a google maps mashup that will show the location of each image I take with my mobile. I am having some trouble with it and have been unable to find anything on google to help me out.
Basically I have a script that will find all images in a folder and put those image names into an array - this is that script:
<?php
// create a handler for the directory
$handler = opendir("images");
// open directory and walk through 开发者_StackOverflow社区the filenames
while ($file = readdir($handler)) {
// if file isn't this directory or its parent, add it to the results
if ($file != "." && $file != "..") {
$results[] = $file;
}
}
// tidy up: close the handler
closedir($handler);
// done!
print_r ($results);
?>
This gives me the following array:
Array
(
[0] => IMAG0005.jpg
[1] => IMAG0030.jpg
)
This part is fine and works as expected. Now I use this array to get the EXIF data that I need from each image. The problem is that if I use an array for the output I get two separate arrays and am unable to do anything with them to create new markers on the map. I use the following code to get the EXIF data
for ($i = 0; $i < count($results); ++$i) {
//print $results[$i];
$arrPhotoExif = exif_read_data('images/'.$results[$i]);
$intLatDeg = GpsDivide($arrPhotoExif["GPSLatitude"][0]);
$intLatMin = GpsDivide($arrPhotoExif["GPSLatitude"][1]);
$intLatSec = GpsDivide($arrPhotoExif["GPSLatitude"][2]);
$intLongDeg = GpsDivide($arrPhotoExif["GPSLongitude"][0]);
$intLongMin = GpsDivide($arrPhotoExif["GPSLongitude"][1]);
$intLongSec = GpsDivide($arrPhotoExif["GPSLongitude"][2]);
// round to 5 = approximately 1 meter accuracy
$intLatitude = round(DegToDec($arrPhotoExif["GPSLatitudeRef"],
$intLatDeg,$intLatMin,$intLatSec),5);
$intLongitude = round(DegToDec($arrPhotoExif["GPSLongitudeRef"],
$intLongDeg,$intLongMin,$intLongSec), 5);
$markers = array("$intLatitude, $intLongitude");
print_r($markers);
That last piece of code prints this as the array:
Array
(
[0] => 51.508742, -0.134583
)
Array
(
[0] => 38.410558, 17.314453
)
I am unable to use this to list the markers - according to google docs the code must look like the following to create new markers on the map.
var marker = new google.maps.Marker({
position: **THIS IS WHERE I NEED TO OUTPUT THE GPS CO-ORDS**,
map: map,
title:"Hello World!"
});
If I try to loop through the markers array I only get one result, obviously as it is creating two arrays with only one piece of data in each.
Can some please help point in the right direction? I want to learn and don't expect to be spoonfed, if someone could just help me get the ball rolling I can pick up from there.
Thank you, I know it's a bit of a long post.
Cheers
I'd suspect you want to build a single array with multiple entries. Instead of:
$markers = array("$intLatitude, $intLongitude");
...try using:
$markers[] = array("$intLatitude, $intLongitude");
That will add the new latitude and longitude string as a new element in the array, rather than overwriting the array each time.
Following the loop, $markers should then contain:
Array
(
[0] => Array
(
[0] => 51.508742, -0.134583
)
[1] => Array
(
[0] => 38.410558, 17.314453
)
)
Which you can then loop through and process as necessary.
精彩评论