Retrieve the Key Number of an Administrative Area (AGS)
Problem
=======
The Geocoder API does not expose the official keys of the German administrative areas, in German: Amtlicher Gemeindeschlüssel (AGS) der gefundenen Gemeinde.
To get this information, you can either use the Map Attributes API as explained in the Map Attributes API Developer Guide.
Solution
========
To request an AGS, do the following:
1. Get the coordinate of a city address from the Geocoder API response:
<br /> https://geocode.search.hereapi.com/v1/geocode?q=Delmenhorst&apiKey=yourapikey<br />
<br /> "position": { "lat": 53.04721, "lng": 8.62881} <br /> 2. Calculate TileId from above coordinate for each administrative level (the city has level 10; county has level 9; state has level 8):<br />
<br /> tileY = Math.floor((position.lat + 90) / degSize)tileX = Math.floor((position.lng + 180) / degSize)tileId = (tileY * 2 * Math.pow(2, level) + tileX)<br />
<br /> Then results: <br /> for Level 10, TileId = 1666097 <br /> for Level 9, TileId = 416280 <br /> for Level 8, TileId = 104204 <br /> (the table of layer names and their levels you can find on this documentation)<br />
3. Specify your request of the tile information from the Map Attributes API for the layers ADMIN_PLACE_8,ADMIN_PLACE_2,ADMIN_PLACE_1 with TileId information retrieved in the previous step.<br /> https://smap.hereapi.com/v8/maps/attributes?in=tile:1666097,416280,104204&apikey=yourapikey&layers=ADMIN_PLACE_8,ADMIN_PLACE_2,ADMIN_PLACE_1<br />
4. Find the Admin Names (check NAMES property for corresponded admin level) from step 1 in the response:<br /> "city": "Delmenhorst" ... "county": "Delmenhorst", ... "state": "Niedersachsen",<br />
Use the attribute Government_Code in these results to determine the code using the following rule:
* + Digit 1 and 2: State (03)
+ Digits 3-5: County (401)
+ Digits 6-8: City (000)
The government code for the city of Delmenhorst is: 03401000.