我正在使用谷歌地理编码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
在ARRAY中获取结果:object(stdClass)#19 (2) { ["results"]=> array(0) { } ["status"]=> string(12) "ZERO_RESULTS" }
答案 0 :(得分:0)
不关心®,它会在转储$ url时由浏览器显示,因为他希望在使用&符时使用字符引用,并且会意外地解析®ion
。
从<br>
,$CompleteAddress
和$address1
删除尾随的$address2
。