0

我正在使用以下代码

$address ='13%2F2%2C+datta+diagambar+soc%2CPune'

$geocode = file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$address.'&sensor=false', true);

$output= json_decode($geocode);

$lat = $output->results[0]->geometry->location->lat;

$long = $output->results[0]->geometry->location->lng;

$lat & $long 是空白的。

请给我一些答案。

4

2 回答 2

2
$url="http://maps.googleapis.com/maps/api/geocode/json?address=$addr&sensor=false";

$json = file_get_contents($url);
$array = json_decode($json, true); //note second parameter on true as we need associative 

 $lat=$array['results'][0]['geometry']['location']['lat'];
 $lang=$array['results'][0]['geometry']['location']['lng'];
 $long_name=$array['results'][0]['address_components'][0]['long_name'];
 $long_name=$array['results'][0]['formatted_address'];

所以你可以访问json内容

于 2014-01-27T04:27:51.223 回答
0
$geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address=13%2F2%2C+datta+diagambar+soc%2CPune&sensor=false');
$outputss= json_decode($geocode);

$lat = $outputss->results[0]->geometry->location->lat;
$long = $outputss->results[0]->geometry->location->lng;
echo $lat." - ".$long;

试试这个

于 2013-02-27T09:29:20.567 回答