【问题标题】:How to determine if address doesn't exists in Google Maps Api v3如何确定 Google Maps Api v3 中是否不存在地址
【发布时间】:2013-01-13 05:05:43
【问题描述】:

您好,我正在尝试使用 google 的 maps API v3 地理编码网络服务来确定某个地址是否存在于 City+Province+Country。我看到谷歌总是返回一些东西。例如,如果我尝试使用http://maps.googleapis.com/maps/api/geocode/json?address=Colon%20100%20,C%C3%B3rdoba,C%C3%B3rdoba,Argentina&sensor=false 查找现有地址:“Colon 100, 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 查找不存在的地址时,例如“nonexistingaddres 2, Córdoba, Córdoba, Argentina”,我也得到了结果。我不知道如何仅通过分析谷歌的响应来找出“不存在”的街道是否存在。 在此先感谢 Mono。

【问题讨论】:

  • 我并不想真正验证和解决问题。我不想显示任何结果,因为 Google 没有找到正确的街道。如果街道不存在,那么我不想显示它。

标签: google-maps google-geocoding-api


【解决方案1】:

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

这并不能阻止人们使用trying to use it

【讨论】:

    【解决方案2】:

    我知道这个问题很老了,但我想我还是会为仍在寻找的人回答这个问题。根据我的经验,处理此问题的最佳方法是查看 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 员工有所帮助。

    【讨论】:

      猜你喜欢
      • 2013-10-05
      • 2012-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-16
      • 1970-01-01
      相关资源
      最近更新 更多