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 に答える