【发布时间】:2013-09-27 02:03:45
【问题描述】:
我注意到我的 google 地理编码已被弃用,并使我的网站陷入瘫痪。我真的可以借助某人的帮助来解决最后一个难题。我的旧代码产生了我网站的其余部分所依赖的单个输出“$Coords”。你能帮我弄清楚如何使新的api具有相同的输出。这是我的旧代码:
$address = str_replace('#', '', $address);
$address = str_replace(' ', '+', $address);
$XMLUrl = 'http://maps.google.com/maps/geo?q='.$address.'&key='.$api.'&sensor=false&output=xml&oe=utf8';
$XMLUrl = 'http://maps.googleapis.com/maps/api/geocode/xml?address='.$address.'&sensor=false';
$XMLContents = file_get_contents($XMLUrl);
$XML = new SimpleXMLElement($XMLContents);
$Coords = explode(',',$XML->Response->Placemark->Point->coordinates);
return $Coords;
这是我对新代码的看法。我只是不知道如何将其输出为 $Coords:
$address = str_replace('#', '', $address);
$address = str_replace(" ", "+", $address);
$json = file_get_contents("http://maps.google.com/maps/api/geocode/json?address=$address&sensor=false®ion=$region");
$json = json_decode($json);
$lat = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lat'};
$long = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lng'};
网站的其余部分取决于存储为 $Coords 而不是 $lat 或 $long 的地理编码。我真的非常感谢我能得到的任何帮助。
【问题讨论】:
-
你见过Upgrade Guide吗,看起来使用XML输出格式会更兼容你的旧代码。你的 $Coords 是什么样的?
-
我尝试了 xml 输出。我可以得到 $lat 和 $long,只是无法让它们输出与 $Coords 相同的值。
标签: google-maps geocoding