这是我发现的随机地址不起作用,但地址存在。
“Team Valley Trading Estate,Gateshead,Tyne and Wear NE92 1DG,UK”
你们可以试试地理编码并告诉我它是否适合你,我有13个地址,12个工作,这1个不工作?
这是我为运行地理编码请求而运行的代码:
class geocoder{
static private $url = "http://maps.google.com/maps/api/geocode/json?sensor=true&address=";
static public function getLocation($address){
$url = self::$url.urlencode($address);
$resp_json = self::curl_file_get_contents($url);
$resp = json_decode($resp_json, true);
if($resp['status']='OK'){
return $resp['results'][0]['geometry']['location'];
}else{
return false;
}
}
static private function curl_file_get_contents($URL){
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $URL);
$contents = curl_exec($c);
curl_close($c);
if ($contents) return $contents;
else return FALSE;
}
}
$address = urlencode("Team Valley Trading Estate, Gateshead, Tyne and Wear NE92 1DG, UK");
$loc = geocoder::getLocation($address);
这证明了地理编码类应该返回数据:
答案 0 :(得分:2)
你 urlencod 两次地址,所以改变:
$address = urlencode("Team Valley Trading Estate, Gateshead, Tyne and Wear NE92 1DG, UK");
到
$address = "Team Valley Trading Estate, Gateshead, Tyne and Wear NE92 1DG, UK";
因为你有 urlencod 'getLocation
函数