【问题标题】:Here API - geocode search using zipcode not returning city fieldHere API - 使用邮政编码的地理编码搜索不返回城市字段
【发布时间】:2021-06-29 03:37:54
【问题描述】:

我正在使用下面的 HERE API 按邮政编码搜索城市和州

https://geocode.search.hereapi.com/v1/geocode?qq=postalCode=43026&apiKey=key&in=countryCode%3AUSA, 但它不是返回城市领域。 结果如下

{ "items": [ { "title": "43026, OH, United States", "id": "here:cm:namedplace:22236211", "resultType": "locality", "localityType": "postalCode", "address": { "label": "43026, OH, United States", "countryCode": "USA", "countryName": "United States", "stateCode": "OH", "state": "Ohio", "postalCode": "43026" }, "position": { "lat": 39.9972, "lng": -83.15518 }, "mapView": { "west": -83.0952, "south": 39.97889, "east": -83.26074, "north": 40.06921 }, "scoring": { "queryScore": 1, "fieldScore": { "postalCode": 1 } } } ] }

谁能帮忙

【问题讨论】:

    标签: javascript here-api geocode


    【解决方案1】:

    如果您对该 API 运行多个查询,您会注意到有些结果包含城市,而有些则不包含。

    例如:

    如果我们运行(将 api 键设置为有效值): https://geocode.search.hereapi.com/v1/geocode?qq=postalCode=60606&apiKey=key&in=countryCode%3AUSA

    我们得到一个这样的地址

    "address": {
                "label": "60606, Chicago, IL, United States",
                "countryCode": "USA",
                "countryName": "United States",
                "stateCode": "IL",
                "state": "Illinois",
                "county": "Cook",
                "city": "Chicago",
                "postalCode": "60606"
            }
    

    其中包括城市值。

    您的查询返回

    "address": {
        "label": "43026, OH, United States",
        "countryCode": "USA",
        "countryName": "United States",
        "stateCode": "OH",
        "state": "Ohio",
        "postalCode": "43026"
    },
    

    缺少城市字段。

    您可以尝试使用 API 文档中提到的 ZIP+4 代码(如果有的话): https://developer.here.com/documentation/geocoding-search-api/dev_guide/topics-api/code-geocode-hpc-hsn.html

    例如, https://geocode.search.hereapi.com/v1/geocode?qq=postalCode=43026-0001&apiKey=key&in=countryCode%3AUSA

    "address": {
        "label": "43026-0001, Hilliard, OH, United States",
        "countryCode": "USA",
        "countryName": "United States",
        "stateCode": "OH",
        "state": "Ohio",
        "county": "Franklin",
        "city": "Hilliard",
        "postalCode": "43026-0001"
    },
    

    会给我们一个城市。

    注意:并非所有 Zip+4 代码都会返回城市名称。例如:43026-0101 不会(这可能是因为它不存在)

    在我看来,没有任何方法可以保证只用邮政编码就可以得到城市字段响应。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-07
      • 2018-10-17
      • 1970-01-01
      相关资源
      最近更新 更多