Reverse geocoding guide

Practical guide with examples: finding the nearest address from coordinates, output formats, detail mode and coordinate order across formats.

Live examples. Requests and responses were made against https://pump.elemroot.com/rgc4 (key key=docs_382d376eaaa6d004b7b93b7d, dataset gl=ee_lt_lv, service s=ADDRESS).
Contents

Endpoint and methods

Uses the GET and POST methods (POST with application/x-www-form-urlencoded). NB: with POST the key must be in the query string (the URL); a key given only in the form body is not seen by the key check and the response is 403.

MethodURL
GEThttps://pump.elemroot.com/rgc4/revgeocode
GEThttps://pump.elemroot.com/rgc4_lyh/revgeocode ("lyh": same API and JSON structure, shorter address form: EE, Tartumaa, Tartu, …)

Parameter reference

ParamMeaningAllowed values / exampleDefault
q *Input point lat,lon (latitude first; repeat = batch)58.3957739,26.7462826—
gl *Dataset. ee_lt_lv_aid adds AADRESS_ID to the detail response (only /rgc4; Estonian, Latvian and Lithuanian points)ee_lt_lv, ee_lt_lv_aid—
s *Rule set; required. The _reverse suffix reverses the component order of the address string (most specific first)ADDRESS, ADDRESS_reverse—
outputOutput formatjson, json2, xml, xml2, kml, ads_liik_staatusjson
key *API key (without it: 403)docs_382d376eaaa6d004b7b93b7d (demo)—
srsInput and output coordinates. distance is in metres only when srs is omitted or is exactly EPSG:4326EPSG:4326, EPSG:3301 (case-insensitive; also wgs84): anything else returns 500EPSG:4326
lMax length of the formatted address in characters (not a level!)integer—
detailAdd structured componentsempty, true, false—
replaceTypeType code rename (repeatable)A5 street—
callbackJSONP callbackfunction name, e.g. cb—

Dataset gl=ee_lt_lv (Estonia+Latvia+Lithuania) is currently the only configured dataset; the service is s=ADDRESS (or s=ADDRESS_reverse: components reversed, see below).

First request

Request
curl "https://pump.elemroot.com/rgc4/revgeocode?q=58.3957739405547,26.7462826320901&gl=ee_lt_lv&s=ADDRESS&key=docs_382d376eaaa6d004b7b93b7d"
Response (json)
[
  {
    "distance": 4.6902068828416404E-4,
    "name": "58.3957739405547,26.7462826320901",
    "placemark": {
      "address": "EE, Tartu maakond, Tartu linn, Tartu linn, Muuseumi tee 2",
      "point": { "coordinates": [26.74628262527919, 58.39577393830106] }
    }
  }
]

distance is the distance between the input point and the found address in metres (the value may come in exponent form, e.g. 4.69E-4 = 0.47 mm). placemark is one object (not an array). name echoes the input coordinates.

Note: distance and srs. The distance is in metres only when srs is omitted or is exactly EPSG:4326 (upper case). Any other spelling: epsg:4326, wgs84 and of course srs=EPSG:3301; makes distance degree-based (the internal computation then runs in planar degrees); do not interpret it as metres in that case. The code itself is case-insensitive (epsg:3301 works); l-est97 does not work in reverse geocoding (500).
Input q = lat,lon. First number is latitude (N), second is longitude (E). System is srs (default EPSG:4326).

How the match is chosen

Every input coordinate returns exactly one match. Several points can be queried in one request by repeating the q parameter; responses come back in the same order.

Near a state border the nearest address point wins regardless of country: a point on the Estonian side may get a Latvian address if the nearest building is in Latvia.

Components reversed (s=ADDRESS_reverse)

The _reverse suffix on the service ID reverses the component order of the address string; most specific first: handy for direct display or shortening. Coordinates, distance and the structured AddressLines (detail) do not change. The suffix is lower case (ADDRESS_REVERSE returns 500).

Request
curl "https://pump.elemroot.com/rgc4/revgeocode?q=58.3957739405547,26.7462826320901&gl=ee_lt_lv&s=ADDRESS_reverse&key=docs_382d376eaaa6d004b7b93b7d"
Response (json)
[
  {
    "distance": 4.6902068828416404E-4,
    "name": "58.3957739405547,26.7462826320901",
    "placemark": {
      "address": "Muuseumi tee 2, Tartu linn, Tartu linn, Tartu maakond, EE",
      "point": { "coordinates": [26.74628262527919, 58.39577393830106] }
    }
  }
]

The same request with s=ADDRESS gives "EE, Tartu maakond, Tartu linn, Tartu linn, Muuseumi tee 2". Works on /rgc4_lyh too ("Muuseumi tee 2, Tartu, Tartu, Tartumaa, EE").

Address components (detail)

By default only address text, coordinates and distance are returned. For structured components add detail (and use json2/xml2):

Request
curl "https://pump.elemroot.com/rgc4/revgeocode?q=58.3957739405547,26.7462826320901&gl=ee_lt_lv&s=ADDRESS&output=json2&detail&key=docs_382d376eaaa6d004b7b93b7d"
Response (json2)
[
  {
    "distance": 4.6902068828416404E-4,
    "name": "58.3957739405547,26.7462826320901",
    "placemark": {
      "address": "EE, Tartu maakond, Tartu linn, Tartu linn, Muuseumi tee 2",
      "AddressDetails": {
        "AddressLines": [
          { "Type": "A0",      "Value": "Eesti Vabariik" },
          { "Type": "A1",      "Value": "Tartu maakond" },
          { "Type": "A2",      "Value": "Tartu linn" },
          { "Type": "A3",      "Value": "Tartu linn" },
          { "Type": "A5",      "Value": "Muuseumi tee" },
          { "Type": "A7",      "Value": "2" },
          { "Type": "POSTCODE","Value": "60532" },
          { "Type": "A1_EHAK", "Value": "0079" },
          { "Type": "A2_EHAK", "Value": "0793" },
          { "Type": "A3_EHAK", "Value": "8151" }
        ]
      },
      "point": { "coordinates": [26.74628262527919, 58.39577393830106] }
    }
  }
]
Note. In json output AddressDetails stays empty ({}) even with detail: typed components come from json2/xml2. detail must be enabled on the server (otherwise HTTP 501).

Latvian and Lithuanian components

Latvian and Lithuanian points use the same type codes, but the set differs:

Output formats

output: json, json2, xml, xml2, kml, ads_liik_staatus.

xml2

curl "https://pump.elemroot.com/rgc4/revgeocode?q=58.3957739405547,26.7462826320901&gl=ee_lt_lv&s=ADDRESS&output=xml2&detail&key=docs_382d376eaaa6d004b7b93b7d"
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<kml xmlns="http://earth.google.com/kml/2.0">
<Response>
<name>58.3957739405547,26.7462826320901</name>
<distance>4.6902068828416404E-4</distance>
<Placemark>
<Point><coordinates>58.39577393830106,26.74628262527919</coordinates></Point>
<address>EE, Tartu maakond, Tartu linn, Tartu linn, Muuseumi tee 2</address>
<AddressDetails>
<AddressLine Type="A0">Eesti Vabariik</AddressLine>
<AddressLine Type="A1">Tartu maakond</AddressLine>
<AddressLine Type="A2">Tartu linn</AddressLine>
<AddressLine Type="A3">Tartu linn</AddressLine>
<AddressLine Type="A5">Muuseumi tee</AddressLine>
<AddressLine Type="A7">2</AddressLine>
<AddressLine Type="POSTCODE">60532</AddressLine>
<AddressLine Type="A1_EHAK">0079</AddressLine>
<AddressLine Type="A2_EHAK">0793</AddressLine>
<AddressLine Type="A3_EHAK">8151</AddressLine>
</AddressDetails>
</Placemark>
</Response>
</kml>

Unlike geocoding, reverse geocoding xml2 has no <AddressLines> wrapper: <AddressLine> elements sit directly under <AddressDetails>.

Coordinate order

Attention: order differs between formats:

Input q is always lat,lon (N,E).

ads_liik_staatus

Address type/status XML, address as Estonian-named fields, with distance:

curl "https://pump.elemroot.com/rgc4/revgeocode?q=58.3957739405547,26.7462826320901&gl=ee_lt_lv&s=ADDRESS&output=ads_liik_staatus&detail&key=docs_382d376eaaa6d004b7b93b7d"
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<aadressideNimekiri>
<aadress>
<aadressSisse>58.3957739405547,26.7462826320901</aadressSisse>
<kaugus>4.6902068828416404E-4</kaugus>
<vaste>
<maakondEhak>0079</maakondEhak>
<maakond>Tartu maakond</maakond>
<omavalitsusEhak>0793</omavalitsusEhak>
<omavalitsus>Tartu linn</omavalitsus>
<asustusyksusEhak>8151</asustusyksusEhak>
<asustusyksus>Tartu linn</asustusyksus>
<liikluspind>Muuseumi tee</liikluspind>
<aadressinumber>2</aadressinumber>
<sihtnumber>60532</sihtnumber>
<aadressValja>EE, Tartu maakond, Tartu linn, Tartu linn, Muuseumi tee 2</aadressValja>
<koordinaadid>26.74628262527919,58.39577393830106</koordinaadid>
</vaste>
</aadress>
</aadressideNimekiri>

Which combination to use

TaskCombinationWhy
Point → address + distance in metresgl=ee_lt_lv&s=ADDRESSdefault EPSG:4326; distance is in metres
Address components as separate fieldsoutput=json2&detail=truereturns AddressLines with type codes
Address fields with Estonian namesoutput=ads_liik_staatus&detail=truedetail is required for this format
Shorter address text/rgc4_lyh/revgeocodesame JSON, shorter address string
Address most-specific-first (Muuseumi tee 2, Tartu linn, …)s=ADDRESS_reverseonly the order of the address string changes; for display and shortening
An address id for the pointgl=ee_lt_lv_aid&detail=trueonly /rgc4; AddressLines gets an AADRESS_ID line for Estonian, Latvian and Lithuanian points alike. /rgc4_lyh does not support it: use the two-step recipe below
Example: address id for a point in one request
curl "https://pump.elemroot.com/rgc4/revgeocode?q=58.3957739,26.7462826&gl=ee_lt_lv_aid&s=ADDRESS&output=json2&detail=true&key=docs_382d376eaaa6d004b7b93b7d"
Response (json2, abridged): the last line is the address id
"AddressLines": [ …, {"Type": "A7", "Value": "2"}, {"Type": "POSTCODE", "Value": "60532"}, …, {"Type": "AADRESS_ID", "Value": "3069760"} ]
Example: the same for a Latvian point
curl "https://pump.elemroot.com/rgc4/revgeocode?q=57.520503,25.390738&gl=ee_lt_lv_aid&s=ADDRESS&output=json2&detail=true&key=docs_382d376eaaa6d004b7b93b7d"
Response (abridged)
"AddressLines": [ …, {"Type": "A7", "Value": "195 k-1"}, {"Type": "POSTCODE", "Value": "4201"}, {"Type": "AADRESS_ID", "Value": "101020361"} ]

A Latvian or Lithuanian AADRESS_ID can be used directly: pass it to geocoding with aidq=true (gl=lv / gl=lt), and with a level prefix also to the address catalogue.

Example: two steps (/rgc4_lyh, which returns no id)
# 1) point -> address text
curl "https://pump.elemroot.com/rgc4/revgeocode?q=58.3957739,26.7462826&gl=ee_lt_lv&s=ADDRESS&key=docs_382d376eaaa6d004b7b93b7d"

# 2) address text -> AADRESS_ID
curl "https://pump.elemroot.com/jgc_rest/geocode?q=Muuseumi+tee+2,+Tartu+linn&gl=ee_aid&output=json2&key=docs_382d376eaaa6d004b7b93b7d"
Two traps. The input q is lat,lon (latitude first), while the JSON response point.coordinates is [E, N]. And distance is in metres only when srs is omitted or is exactly EPSG:4326; srs=EPSG:3301, but also epsg:4326 or wgs84, yield a degree-based number.

Error handling

SituationCodeMessage
gl missing500No service provided in the request. Use request parameter gl
Dataset not supported500<gl>: this service is not supported
q missing400q missing in query
q invalid400q is not correct
l invalid400l is not correct
detail disabled in servlet501detail is not supported by this servlet
Format requires detail=true400output format <x> only supported with URL parameter detail=true
Unknown output400<format>: unknown output format
Authorisation error (key)403key error message

API reference (Swagger UI) â†’ Interactive try-it-out. OpenAPI spec (YAML file) â†’ Machine-readable API description for tooling. Note: opens as a raw YAML file.