Skip to content
Geocoding

Endpoints

Geocoding

One endpoint in two directions: a place name or address to coordinates (q), or coordinates to the nearest place (lat & lon).

Request

GET/v1/geocode

Requires an API key in the Authorization header. See Authentication.

Parameters

Parameters
NameTypeDescription
qoptionalstringForward geocoding: place name or address, 2 to 200 characters, with at least 2 letters or digits. Latin and Cyrillic are both supported, for example Sukhbaatar Square or Сүхбаатарын талбай.
limitoptionalintegerForward geocoding: maximum number of results, 1 to 20. Default 5.
latoptionalnumberReverse geocoding: latitude in decimal degrees (WGS84), −90 to 90.
lonoptionalnumberReverse geocoding: longitude in decimal degrees (WGS84), −180 to 180.

Example

curl -G "https://developers.ubhub.mn/v1/geocode" \
  --data-urlencode "q=Sukhbaatar Square" \
  -d limit=5 \
  -H "Authorization: Bearer YOUR_API_KEY"

Response

200 OK
{
  "query": "Sukhbaatar",
  "results": [
    {
      "id": "loc_3f2a9c1d8e7b6a50",
      "name": "Sukhbaatar District",
      "address": "7-р хороо, Сүхбаатар, Mongolia",
      "latitude": 47.92662,
      "longitude": 106.929681,
      "type": "poi"
    },
    {
      "id": "loc_9b1e4d7c2a6f3e81",
      "name": "Sukhbaatar District General Hospital",
      "address": "11-р хороо, Сүхбаатар, Mongolia",
      "latitude": 47.931345,
      "longitude": 106.928361,
      "type": "poi"
    }
  ],
  "count": 2
}
Response fields
FieldTypeDescription
querystringThe search text, with whitespace normalized.
resultsarrayMatches, best first.
results[].idstringOpaque, stable identifier of the place.
results[].namestringDisplay name.
results[].addressstring | nullAddress or area the place is in.
results[].latitudenumberLatitude (WGS84), up to 6 decimals.
results[].longitudenumberLongitude (WGS84), up to 6 decimals.
results[].typestringResult category in lower case, for example poi for a point of interest, or place when no category is known.
countintegerNumber of results in this response.

No match is not an error: you get 200 OK with an empty list.

200 OK (no match)
{
  "query": "Nowhere Street",
  "results": [],
  "count": 0
}

Ranking

Results are ordered by how well the name matches the query:

  1. Exact name matches.
  2. Names that start with the query.
  3. Names where every word of the query starts a word.
  4. Names that contain every word of the query.

Within each group, more prominent places come first, then shorter names.

Building autocomplete

Wait about 300 ms after the last keystroke before sending a request, cancel the previous request when a new one starts (in JavaScript, pass an AbortController signal to fetch), and do not search until the user has typed at least 2 characters.

Reverse geocoding

Send lat and lon instead of q to turn a coordinate into the nearest meaningful place. The response is the same shape as a forward search, with one result: type is the match kind (address, place or street) and distance_meters is how far the match is from your point. Nothing found nearby is 200 OK with an empty results list, not an error. Send either q or both lat and lon, never both and never neither.

curl -G "https://developers.ubhub.mn/v1/geocode" \
  -d lat=47.9184 \
  -d lon=106.9177 \
  -H "Authorization: Bearer YOUR_API_KEY"

Errors

Errors
StatusCodeMeaning
400INVALID_REQUESTA parameter is missing or invalid. details.field names it. Also used with status 405 for a wrong HTTP method and 413 for an oversized body.
401INVALID_API_KEYThe Authorization header is missing or malformed, the key does not exist, or it has expired (details.reason is expired).
403API_KEY_REVOKEDThe key was revoked in the dashboard.
403ENDPOINT_NOT_ALLOWEDThe key is not allowed to call this endpoint. Each key is limited to the endpoints chosen when it was created; details.allowed_endpoints lists them.
408REQUEST_TIMEOUTThe data service behind the API did not answer in time.
429RATE_LIMIT_EXCEEDEDThe key used up its requests for the current one-minute window.
500INTERNAL_ERRORAn unexpected error in the API.
502UPSTREAM_ERRORThe data service behind the API failed or returned an invalid answer.
503SERVICE_UNAVAILABLEThe service is temporarily unavailable, for example while a data source is being configured or loaded.

See Errors for the response format and how to handle each code.

Try it

Send a real request with one of your keys.

GET/v1/geocodePlayground
Parameters

Place name or address, 2–200 characters. (Reverse geocoding uses lat & lon; see the docs.)

Maximum results, 1–20.

Authorization

Loading your keys…

Request

GET /v1/geocode?q=Sukhbaatar%20Square&limit=5
curl "https://developers.ubhub.mn/v1/geocode?q=Sukhbaatar%20Square&limit=5" \
  -H "Authorization: Bearer YOUR_API_KEY"

Response

Send a request to see the response.