0

有没有办法使用地理编码或任何其他谷歌 API 来获取与特定邮政编码相关的所有县?

我只能将地理编码 API 用于项目。当用户输入美国邮政编码时,我需要返回与该邮政编码相关的县列表。当我尝试使用地理编码 API 执行此操作时,当有多个县与该邮政编码相关联时,我不会返回一个县。

邮政编码 01011 有两个与之相关的县。

以下是 smartystreets 的响应,您可以看到它返回“county_name”,但也返回一个名为“alternate_counties”的数组

当我用谷歌地理编码尝试这个时,我没有得到一个县。下面还有例子

智慧街

邮政编码 API 页面 https://www.smartystreets.com/products/apis/us-zipcode-api

https://us-zipcode.api.smartystreets.com/lookup?key=[KEY]&zipcode=01011

[
    {
        "input_index": 0,
        "city_states": [
            {
                "city": "Chester",
                "state_abbreviation": "MA",
                "state": "Massachusetts",
                "mailable_city": true
            }
        ],
        "zipcodes": [
            {
                "zipcode": "01011",
                "zipcode_type": "S",
                "default_city": "Chester",
                "county_fips": "25013",
                "county_name": "Hampden",
                "state_abbreviation": "MA",
                "state": "Massachusetts",
                "latitude": 42.29292,
                "longitude": -72.96728,
                "precision": "Zip5",
                "alternate_counties": [
                    {
                        "county_fips": "25015",
                        "county_name": "Hampshire",
                        "state_abbreviation": "MA",
                        "state": "Massachusetts"
                    }
                ]
            }
        ]
    }
]

谷歌地理编码

https://maps.googleapis.com/maps/api/geocode/json?address=01011&key=[KEY]

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "01011",
               "short_name" : "01011",
               "types" : [ "postal_code" ]
            },
            {
               "long_name" : "Chester",
               "short_name" : "Chester",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Massachusetts",
               "short_name" : "MA",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "United States",
               "short_name" : "US",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Chester, MA 01011, USA",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 42.388329,
                  "lng" : -72.8806019
               },
               "southwest" : {
                  "lat" : 42.2371459,
                  "lng" : -73.0364828
               }
            },
            "location" : {
               "lat" : 42.2987566,
               "lng" : -72.96967789999999
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 42.388329,
                  "lng" : -72.8806019
               },
               "southwest" : {
                  "lat" : 42.2371459,
                  "lng" : -73.0364828
               }
            }
         },
         "place_id" : "ChIJGWJtcKs754kRrWCx_cmoyWE",
         "types" : [ "postal_code" ]
      }
   ],
   "status" : "OK"
}
4

0 回答 0