Reverse geocoding
Coordinates in, the nearest address out, or the locality, region or country if that is all you want.
GEThttps://api.mygeocode.com/v1/reverse
Parameters
| Parameter | Type | Description |
|---|---|---|
latrequired | number | -90 to 90. |
lonrequired | number | -180 to 180. |
leveloptional | string | The most specific level to return: address (default), street, postcode, city, region, country. Coarser levels are faster and never fall below the requested level. |
radiusoptional | integer | Search radius in metres for addresses, 1 to 5000. Default 5000. Set it small to get null instead of a far-away address. |
langoptional | string | ISO 639-1 code for names. Default en. |
keyoptional | string | API key, if not sent as a header. |
Example
$ curl "https://api.mygeocode.com/v1/reverse?lat=41.8902&lon=12.4922&lang=it"const url = new URL("https://api.mygeocode.com/v1/reverse");
url.searchParams.set("lat", 41.8902);
url.searchParams.set("lon", 12.4922);
url.searchParams.set("lang", "it");
const { result } = await (await fetch(url)).json();
console.log(result ? result.formatted : "nothing nearby");import requests
r = requests.get("https://api.mygeocode.com/v1/reverse",
params={"lat": 41.8902, "lon": 12.4922, "lang": "it"}, timeout=10)
result = r.json()["result"]
print(result["formatted"] if result else "nothing nearby")Response
{
"status": "ok",
"lat": 41.8902,
"lon": 12.4922,
"result": {
"formatted": "Piazza del Colosseo 1, 00184 Roma RM, Italia",
"lat": 41.890251,
"lon": 12.492373,
"distance_m": 9,
"type": "address",
"precision": "house",
"place_id": "it.addr.5d09aa31",
"components": {
"house_number": "1",
"road": "Piazza del Colosseo",
"suburb": "Municipio Roma I",
"city": "Roma",
"county": "Roma",
"state": "Lazio",
"postcode": "00184",
"country": "Italia",
"country_code": "it"
}
}
}Response fields
| Field | Type | Description |
|---|---|---|
lat, lon | number | The point you sent, echoed. |
result | object or null | null when nothing is within radius at the requested level. |
result.formatted | string | The address, or the locality name for coarser levels. |
result.lat, result.lon | number | The position of the returned feature, not your point. |
result.distance_m | integer | Metres from your point to the feature. 0 when the point is inside it. |
result.type, result.precision, result.place_id, result.components | As in forward geocoding. |
Notes
- A large
distance_mis a signal. A point in a park may be 300 m from the nearest address; in that case showing the neighbourhood is usually better than showing the address. level=countryanswers in about a millisecond and is the cheapest way to answer "which country is this point in".- Points at sea return
nullataddresslevel and, within territorial waters, the country atcountrylevel.
The same lookup in other providers' formats
If you already have code written against one of these providers, keep it: the drop-in host accepts the same path and parameters and answers in that provider's response shape, with this endpoint behind it. See how the drop-ins work.
| Provider | Host | Path |
|---|---|---|
| Google Maps Platform | gapi.mygeocode.com | /maps/api/geocode/json?latlng=lat,lng |
| Bing Maps REST Services | bing.mygeocode.com | /REST/v1/Locations/{lat},{lon} |
| HERE Geocoding and Search | here.mygeocode.com | /v1/revgeocode?at=lat,lng |
| Mapbox Geocoding | mapbox.mygeocode.com | /geocoding/v5/mapbox.places/{lon},{lat}.json/search/geocode/v6/reverse?longitude=...&latitude=... |
| Geocode.Farm | farm.mygeocode.com | /reverse/?lat=...&lon=.../v3/json/reverse/?lat=...&lon=... |
| OpenStreetMap Nominatim | osm.mygeocode.com | /reverse?lat=...&lon=...&format=json |
| OpenCage | opencage.mygeocode.com | /geocode/v1/json?q=lat,lng |
| LocationIQ | locationiq.mygeocode.com | /v1/reverse?lat=...&lon=...&format=json |
| Geoapify | geoapify.mygeocode.com | /v1/geocode/reverse?lat=...&lon=... |
| TomTom Search | tomtom.mygeocode.com | /search/2/reverseGeocode/{lat},{lon}.json |
| MapQuest Geocoding | mapquest.mygeocode.com | /geocoding/v1/reverse?location=lat,lng |
| Geocodio | geocodio.mygeocode.com | /v1.7/reverse?q=lat,lng |
| PositionStack | positionstack.mygeocode.com | /v1/reverse?query=lat,lng |
Errors
400 invalid_request when lat or lon is missing or out of range, or level is not one of the listed values.