1

您好我正在尝试使用谷歌的地图 API v3 地理编码网络服务来确定某个城市+省+国家中是否存在地址。我看到谷歌总是返回一些东西。例如,如果我尝试使用http://maps.googleapis.com/maps/api/geocode/json?address=Colon%20100%20 查找现有地址:“Colon 100, Córdoba, Córdoba, Argentina”, C%C3%B3rdoba,C%C3%B3rdoba,Argentina&sensor=false我得到了一些东西。但是,当我尝试使用以下方式查找不存在的地址时,例如“nonexistingaddres 2, Córdoba, Córdoba, Argentina”:http ://maps.googleapis.com/maps/api/geocode/json?address=nonexistingaddress%20100,C% C3%B3rdoba,C%C3%B3rdoba,Argentina&sensor=false我也得到一个结果。我不知道如何仅通过分析谷歌的响应来找出“不存在”的街道是否存在。在此先感谢,单声道。

4

2 回答 2

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 员工有所帮助。

于 2014-12-17T22:28:37.683 回答
2

Google Maps API v3 地理编码器不是地址验证器。其目的是找到给定(邮政)地址的最佳坐标。

这并不能阻止人们尝试使用它

于 2013-01-29T16:14:43.823 回答