我正在使用以下代码
$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是空白的。
请给我一些答案。
答案 0 :(得分: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内容
答案 1 :(得分: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;
试试这个