如何从HERE API获得给定城市内给定半径内的所有城市?

时间:2019-04-27 17:35:00

标签: here-api

我需要能够提供半径的城市/州或邮政编码以及整数,并使用HERE返回给定半径内的所有城市/邮政编码,但是文档似乎尚不清楚。

https://geocoder.api.here.com/6.2/reversegeocode.json?app_id=xxx&app_code=xxxx

返回值为:

<ns2:Error xmlns:ns2="http://www.navteq.com/lbsp/Errors/1" type="PermissionError" subtype="InvalidCredentials">
  <Details>invalid credentials for xxxxxxx</Details>
</ns2:Error>

但是当我使用

https://geocoder.api.here.com/6.2/geocode.json?app_id=xxx&app_code=xxxx

我取回数据。

值得一提的是,我正在使用REST API的Freemium软件包

那么首先为什么我不能从反向地理编码API取回数据?

完成上述操作的合适字符串是什么?

更新

将其余部分留在这里,以防其他人遇到。要使用反向地理编码,API路由实际上是

https://reverse.geocoder.api.here.com/6.2/reversegeocode.json

尽管我仍然需要一些有关如何获取半径数据的帮助

更新2:

https://reverse.geocoder.api.here.com/6.2/reversegeocode.json?app_id=x&app_code=x&level=city&mode=retrieveAreas&prox=52.5309,13.3847,80467.2

返回:

{
  "Response": {
    "MetaInfo": {
      "Timestamp": "2019-04-27T17:47:41.043+0000"
    },
    "View": [
      {
        "_type": "SearchResultsViewType",
        "ViewId": 0,
        "Result": [
          {
            "Relevance": 1,
            "Distance": 0,
            "Direction": 0,
            "MatchLevel": "district",
            "MatchQuality": {
              "Country": 1,
              "State": 1,
              "County": 1,
              "City": 1,
              "District": 1,
              "PostalCode": 1
            },
            "Location": {
              "LocationId": "NT_0ES-GaH3lZzJCuLQBrdw7C",
              "LocationType": "point",
              "DisplayPosition": {
                "Latitude": 52.5309,
                "Longitude": 13.3847
              },
              "MapView": {
                "TopLeft": {
                  "Latitude": 52.54063,
                  "Longitude": 13.36566
                },
                "BottomRight": {
                  "Latitude": 52.50407,
                  "Longitude": 13.42964
                }
              },
              "Address": {
                "Label": "Mitte, Berlin, Deutschland",
                "Country": "DEU",
                "State": "Berlin",
                "County": "Berlin",
                "City": "Berlin",
                "District": "Mitte",
                "PostalCode": "10178",
                "AdditionalData": [
                  {
                    "value": "Deutschland",
                    "key": "CountryName"
                  },
                  {
                    "value": "Berlin",
                    "key": "StateName"
                  },
                  {
                    "value": "Berlin",
                    "key": "CountyName"
                  }
                ]
              },
              "MapReference": {
                "ReferenceId": "53500282",
                "SideOfStreet": "neither",
                "CountryId": "20147700",
                "StateId": "20187401",
                "CountyId": "20187402",
                "CityId": "20187403",
                "DistrictId": "20187417"
              }
            }
          }
        ]
      }
    ]
  }
}

文档说要输入坐标和半径(即50英里),所以不确定为什么我只收到一个城市柏林。

更新3:

https://reverse.geocoder.api.here.com/6.2/multi-reversegeocode.json?app_id=x&app_code=x&level=city&mode=retrieveAreas&prox=60.5544,-151.2583,80000

尝试过multi-reversegeocode

返回值为:{}

1 个答案:

答案 0 :(得分:1)

获取附近半径的城市

使用具有以下参数的反向地理编码端点

https://reverse.geocoder.api.here.com/6.2/reversegeocode.json?
prox=52.5309,13.3847,80500   /* Note: 80.5 km around Berlin */
&app_id=YOUR_APP_ID
&app_code=YOUR_APP_CODE
&mode=retrieveAreas
&level=city
&gen=9

简而言之,除了缺少gen查询参数之外,“更新2”中的示例是正确的。实际上,根据API Reference,查询参数level仅与gen=2或更高版本结合使用才有效。

相关问题