首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google Maps mashup的PHP和EXIF数据

Google Maps mashup的PHP和EXIF数据
EN

Stack Overflow用户
提问于 2011-08-24 23:24:54
回答 1查看 745关注 0票数 1

我正在尝试创建一个google地图mashup,它将显示我用手机拍摄的每个图像的位置。我遇到了一些麻烦,在谷歌上找不到任何可以帮助我的东西。

基本上,我有一个脚本,它将查找文件夹中的所有图像,并将这些图像名称放入一个数组中-这就是该脚本:

代码语言:javascript
复制
<?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);     
?>

这给我提供了以下数组:

代码语言:javascript
复制
Array
(
    [0] => IMAG0005.jpg
    [1] => IMAG0030.jpg
)

这部分很好,并按预期工作。现在,我使用这个数组从每个图像中获取所需的EXIF数据。问题是,如果我使用一个数组作为输出,我会得到两个独立的数组,并且无法使用它们在地图上创建新的标记。我使用以下代码来获取EXIF数据

代码语言:javascript
复制
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);

最后一段代码将其输出为数组:

代码语言:javascript
复制
Array
(
    [0] => 51.508742, -0.134583
)
Array
(
    [0] => 38.410558, 17.314453
)

我不能使用这个来列出标记-根据谷歌文档,代码必须像下面这样在地图上创建新的标记。

代码语言:javascript
复制
var marker = new google.maps.Marker({
    position: **THIS IS WHERE I NEED TO OUTPUT THE GPS CO-ORDS**, 
    map: map,
    title:"Hello World!"
});

如果我尝试遍历标记数组,我只得到一个结果,显然是因为它创建了两个数组,每个数组中只有一段数据。

能帮我指出正确的方向吗?我想要学习,并不期望被用汤匙喂养,如果有人能帮我把球滚动起来,我就可以从那里拿起。

谢谢,我知道这篇文章有点长。

干杯

EN

回答 1

Stack Overflow用户

发布于 2011-08-24 23:33:16

我怀疑您想要构建一个具有多个条目的单个数组。而不是:

代码语言:javascript
复制
$markers = array("$intLatitude, $intLongitude");

...try使用:

代码语言:javascript
复制
$markers[] = array("$intLatitude, $intLongitude");

这会将新的纬度和经度字符串作为新元素添加到数组中,而不是每次都覆盖数组。

在循环之后,$markers应该包含:

代码语言:javascript
复制
Array
(
    [0] => Array
        (
            [0] => 51.508742, -0.134583
        )

    [1] => Array
        (
            [0] => 38.410558, 17.314453
        )

)

然后,您可以根据需要对其进行循环和处理。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7178051

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档