我目前正在使用谷歌地理编码 API 从地址获取 LatLong,但它不能正确显示结果。请告诉我的代码有什么问题。提前谢谢。
代码 :
$address1=$this->input->post("Deal_Address1")."<br>";
$address2=$this->input->post("Deal_Address2")."<br>";
$CompleteAddress=$address1."".$address2."<br>";
$address=str_replace(' ','+',$CompleteAddress);
$address=str_replace(',','+',$address);
$url = "http://maps.google.com/maps/api/geocode/json?address=$address&sensor=false®ion=Israel";
$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);
//var_dump($response_a);
if(isset($response_a->results[0])>0){
$latitude = $response_a->results[0]->geometry->location->lat."<br>";
$longitude = $response_a->results[0]->geometry->location->lng."<br>"; }else{
$latitude=0.00;
$longitude=0.00;
}
$url=http://maps.google.com/maps/api/geocode/json?address=32+Lehi+Street+Jerusalem&sensor=false®ion=Israel
在数组中获取结果:object(stdClass)#19 (2) { ["results"]=> array(0) { } ["status"]=> string(12) "ZERO_RESULTS" }