0

我注意到我的谷歌地理编码已被弃用,并使我的网站陷入瘫痪。我真的可以借助某人的帮助来解决最后一个难题。我的旧代码产生了我网站的其余部分所依赖的单个输出“$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&region=$region");
$json = json_decode($json);
$lat = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lat'};
$long = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lng'};

网站的其余部分取决于存储为 $Coords 而不是 $lat 或 $long 的地理编码。我真的很感激我能得到的任何帮助。

4

1 回答 1

0

我需要将它保存为一个数组。呵呵

$Coords = $long.', '.$lat;
$Coords = explode(',',$Coords);
于 2013-09-27T03:33:43.580 回答