Reverse geocoding guide
Practical guide with examples: finding the nearest address from coordinates, output formats, detail mode and coordinate order across formats.
https://pump.elemroot.com/rgc4 (key key=docs_382d376eaaa6d004b7b93b7d, dataset
gl=ee_lt_lv, service s=ADDRESS).
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.
| Method | URL |
|---|---|
GET | https://pump.elemroot.com/rgc4/revgeocode |
GET | https://pump.elemroot.com/rgc4_lyh/revgeocode ("lyh": same API and JSON structure, shorter address form: EE, Tartumaa, Tartu, …) |
Parameter reference
| Param | Meaning | Allowed values / example | Default |
|---|---|---|---|
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 | — |
output | Output format | json, json2, xml, xml2, kml, ads_liik_staatus | json |
key * | API key (without it: 403) | docs_382d376eaaa6d004b7b93b7d (demo) | — |
srs | Input and output coordinates. distance is in metres only when srs is omitted or is exactly EPSG:4326 | EPSG:4326, EPSG:3301 (case-insensitive; also wgs84): anything else returns 500 | EPSG:4326 |
l | Max length of the formatted address in characters (not a level!) | integer | — |
detail | Add structured components | empty, true, false | — |
replaceType | Type code rename (repeatable) | A5 street | — |
callback | JSONP callback | function 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
Requestcurl "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.
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).
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.
- If the nearest address point (a building) is within roughly 300 m, the building address is returned.
- If there is no building nearby (forest, field, water, highway), an administrative level is returned: a village or small town in Estonia, a pagasts or town in Latvia, a seniūnija with its municipality in Lithuania.
- A point far from all addresses and administrative units (open sea, for example) returns the
country level or an empty component list (
AddressLines: []).
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).
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):
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] }
}
}
]
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:
A4,A6andA8do not appear in Latvian or Lithuanian responses; no country returns apartments in reverse geocoding.- On Latvian addresses
A7can also be a house name (Riņņi), not a number. POSTCODEcomes without the country prefix (2127, notLV-2127).- For a house without a street the house name follows the settlement in the address text
(
…, Vecates pag., Riņņi); in Lithuania the form is…, Matukų k. 11.
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
- JSON / JSON2:
point.coordinates=[E, N]=[longitude, latitude] - XML / XML2 / KML:
<coordinates>=N,E=latitude,longitude - ads_liik_staatus:
<koordinaadid>=E,N=longitude,latitude
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
| Task | Combination | Why |
|---|---|---|
| Point → address + distance in metres | gl=ee_lt_lv&s=ADDRESS | default EPSG:4326; distance is in metres |
| Address components as separate fields | output=json2&detail=true | returns AddressLines with type codes |
| Address fields with Estonian names | output=ads_liik_staatus&detail=true | detail is required for this format |
| Shorter address text | /rgc4_lyh/revgeocode | same JSON, shorter address string |
Address most-specific-first (Muuseumi tee 2, Tartu linn, …) | s=ADDRESS_reverse | only the order of the address string changes; for display and shortening |
| An address id for the point | gl=ee_lt_lv_aid&detail=true | only /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 |
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.
/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"
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
| Situation | Code | Message |
|---|---|---|
gl missing | 500 | No service provided in the request. Use request parameter gl |
| Dataset not supported | 500 | <gl>: this service is not supported |
q missing | 400 | q missing in query |
q invalid | 400 | q is not correct |
l invalid | 400 | l is not correct |
detail disabled in servlet | 501 | detail is not supported by this servlet |
Format requires detail=true | 400 | output format <x> only supported with URL parameter detail=true |
Unknown output | 400 | <format>: unknown output format |
| Authorisation error (key) | 403 | key error message |