您好我正在尝试使用Google地图API v3地理编码网络服务查明City + Province + Country中是否存在地址。我看到谷歌总是会回报一些东西。例如,如果我试图找到一个现有地址:“Colon 100,Córdoba,Córdoba,Argentina”使用:http://maps.googleapis.com/maps/api/geocode/json?address=Colon%20100%20,C%C3%B3rdoba,C%C3%B3rdoba,Argentina&sensor=false我得到了一些东西。但当我尝试使用:http://maps.googleapis.com/maps/api/geocode/json?address=nonexistingaddress%20100,C%C3%B3rdoba,C%C3%B3rdoba,Argentina&sensor=false找到并且不存在的地址,例如“nonxistingaddres 2,Córdoba,Córdoba,Argentina”时,我也得到了一个结果。通过分析谷歌的回应,我不知道如何找出“不存在”的街道是否存在。 提前谢谢,Mono。
答案 0 :(得分:3)
我知道这个问题已经过时了,但我想我仍然会回答那些仍在寻找的人。根据我的经验,处理此问题的最佳方法是查看API响应。我不会使用谷歌地图进行地址验证,只是为了查找坐标,但如果某人提供的地址无效(至少就谷歌而言)我需要正确失败,因为它不会返回可用我的应用程序使用的纬度/经度。
在PHP中,我做了类似的事情:
public static function latlong($location) {
if ($location!='') {
try {
$json = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($location));
$parsedjson = json_decode($json, true);
if (key_exists(0,$parsedjson['results'])) {
$lat_long_array = $parsedjson['results'][0]['geometry']['location'];
return $lat_long_array;
} else {
return false;
}
} catch (Exception $e) {
//echo 'Caught exception: ', $e->getMessage(), "\n";
return false;
}
}
}
希望能帮助任何到此结束的Google员工。
答案 1 :(得分:2)
Google Maps API v3 geocoder不是地址验证程序。其目的是找到给定(邮政)地址的最佳坐标。
这不会阻止人们离开trying to use it