我正在尝试创建一个google地图mashup,它将显示我用手机拍摄的每个图像的位置。我遇到了一些麻烦,在谷歌上找不到任何可以帮助我的东西。
基本上,我有一个脚本,它将查找文件夹中的所有图像,并将这些图像名称放入一个数组中-这就是该脚本:
<?php
// create a handler for the directory
$handler = opendir("images");
// open directory and walk through 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);
?>这给我提供了以下数组:
Array
(
[0] => IMAG0005.jpg
[1] => IMAG0030.jpg
)这部分很好,并按预期工作。现在,我使用这个数组从每个图像中获取所需的EXIF数据。问题是,如果我使用一个数组作为输出,我会得到两个独立的数组,并且无法使用它们在地图上创建新的标记。我使用以下代码来获取EXIF数据
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);最后一段代码将其输出为数组:
Array
(
[0] => 51.508742, -0.134583
)
Array
(
[0] => 38.410558, 17.314453
)我不能使用这个来列出标记-根据谷歌文档,代码必须像下面这样在地图上创建新的标记。
var marker = new google.maps.Marker({
position: **THIS IS WHERE I NEED TO OUTPUT THE GPS CO-ORDS**,
map: map,
title:"Hello World!"
});如果我尝试遍历标记数组,我只得到一个结果,显然是因为它创建了两个数组,每个数组中只有一段数据。
能帮我指出正确的方向吗?我想要学习,并不期望被用汤匙喂养,如果有人能帮我把球滚动起来,我就可以从那里拿起。
谢谢,我知道这篇文章有点长。
干杯
发布于 2011-08-24 23:33:16
我怀疑您想要构建一个具有多个条目的单个数组。而不是:
$markers = array("$intLatitude, $intLongitude");...try使用:
$markers[] = array("$intLatitude, $intLongitude");这会将新的纬度和经度字符串作为新元素添加到数组中,而不是每次都覆盖数组。
在循环之后,$markers应该包含:
Array
(
[0] => Array
(
[0] => 51.508742, -0.134583
)
[1] => Array
(
[0] => 38.410558, 17.314453
)
)然后,您可以根据需要对其进行循环和处理。
https://stackoverflow.com/questions/7178051
复制相似问题