【问题标题】:Google Geocode API only USA results仅限 Google Geocode API 美国结果
【发布时间】:2013-10-31 21:01:42
【问题描述】:

我正在使用 Google 提供的用于邮政编码查找的简单 URL。

http://maps.googleapis.com/maps/api/geocode/json?address=90210&sensor=true

此 URL 将返回全世界的结果,但我如何将这些结果限制在美国?我查了一下,但找不到任何东西。当可能有办法添加到 URL 并获取:

  {
  "results" : [],
  "status" : "ZERO_RESULTS"
  }

如果根本没有结果,这就是 API 返回的内容。容易得多。

【问题讨论】:

    标签: geocoding google-geocoder


    【解决方案1】:
    【解决方案2】:

    当您尝试您在问题中提供的链接时,也许 Google 出现了故障。我刚刚试了一下,效果很好:

    {
       "results" : [
          {
             "address_components" : [
                {
                   "long_name" : "90210",
                   "short_name" : "90210",
                   "types" : [ "postal_code" ]
                },
                {
                   "long_name" : "Beverly Hills",
                   "short_name" : "Beverly Hills",
                   "types" : [ "locality", "political" ]
                },
                {
                   "long_name" : "Los Angeles County",
                   "short_name" : "Los Angeles County",
                   "types" : [ "administrative_area_level_2", "political" ]
                },
                {
                   "long_name" : "California",
                   "short_name" : "CA",
                   "types" : [ "administrative_area_level_1", "political" ]
                },
                {
                   "long_name" : "United States",
                   "short_name" : "US",
                   "types" : [ "country", "political" ]
                }
             ],
             "formatted_address" : "Beverly Hills, CA 90210, USA",
             "geometry" : {
                "bounds" : {
                   "northeast" : {
                      "lat" : 34.1354771,
                      "lng" : -118.3867129
                   },
                   "southwest" : {
                      "lat" : 34.065094,
                      "lng" : -118.4423781
                   }
                },
                "location" : {
                   "lat" : 34.1030032,
                   "lng" : -118.4104684
                },
                "location_type" : "APPROXIMATE",
                "viewport" : {
                   "northeast" : {
                      "lat" : 34.1354771,
                      "lng" : -118.3867129
                   },
                   "southwest" : {
                      "lat" : 34.065094,
                      "lng" : -118.4423781
                   }
                }
             },
             "types" : [ "postal_code" ]
          }
       ],
       "status" : "OK"
    }
    

    【讨论】:

    • 对不起,我以为我说清楚了,但我想我错过了。该 URL 确实返回结果。我把它作为一个例子,但是如果你输入一组随机的 5 个数字作为 zip,你会得到上面的“ZERO_RESULTS”。但是,我使用变通方法让它工作。可以发誓我已经在这里发布了这个发现。我所做的是获得一个包含状态及其缩写的数组,并在我从 Geocode API 获得结果时搜索该数组。如果缩写不存在,我会抛出一个错误,否则我会运行其余的代码。很简单。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-25
    相关资源
    最近更新 更多