[英]latitude and longitude automatically using php, API
我尝试使用提出的答案: 使用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
做这样的事情
if($response!="")
{
$response_a = json_decode($response);
if(isset($response_a->results[0]))
{
echo $lat = $response_a->results[0]->geometry->location->lat;
echo "<br />";
echo $long = $response_a->results[0]->geometry->location->lng;
}
else
{
echo "result is not set in response";
}
}
else
{
echo "No respnse ";
}
我在PHP 5.5.11机器上测试了您的代码,它可以工作。
尝试添加error_reporting(E_ALL);
直接在<?php
。
您确定卷曲模块已启用吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.