这是我发现的一个随机地址不起作用,但该地址仍然存在。
"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);
这证明地理编码类应该返回数据: