【发布时间】:2014-10-19 10:06:19
【问题描述】:
我尝试使用建议的答案:Get latitude and longitude automatically using php, API
$address = "India+Panchkula";
$url = "http://maps.google.com/maps/api/geocode/json?address=$address&sensor=false®ion=India";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
$response_a = json_decode($response);
echo $lat = $response_a->results[0]->geometry->location->lat;
echo "<br />";
echo $long = $response_a->results[0]->geometry->location->lng;
但我总是遇到 3 个错误
未定义的偏移量:0 并试图获取非对象的属性
这些错误对应于存在的行:
$lat = $response_a->results[0]->geometry->location->lat;
$long = $response_a->results[0]->geometry->location->lng;
有没有人经历过这些?我正在使用 php 5.5
【问题讨论】:
-
你确定这是唯一涉及的代码吗?作品fine
标签: php google-maps-api-3