← Back to docs
endpoints
POST locci/geo/city/nearest/

Nearest city to a given latitude/longitude coordinate.

Locci Geography

Overview

Returns the single city in the database closest to a given latitude and longitude coordinate pair. Uses PostGIS spatial indexing for efficient distance computation across the full city dataset. The response includes the city name, its own coordinates, the distance from the query point in kilometres, and full geographic context (country, region, continent). Useful for reverse geocoding — converting a raw coordinate (e.g. from a device GPS) into a named place.


Request parameters

Name Type In Required Description Example
lat Float Body Yes Observer latitude in decimal degrees. Valid range: -90.0 (South Pole) to 90.0 (North Pole). Used to compute the observer's position on Earth's surface for all sky calculations.
lon Float Body Yes Observer longitude in decimal degrees. Valid range: -180.0 to 180.0. Negative values are west of the Prime Meridian, positive values are east.

Response fields

Name Type Nullable Description Example
results Object Object containing the single city closest to the submitted coordinates.
results.admin1 String Region/state/province code (admin level 1). BC
results.admin1_id Integer Primary key of the region record. 75
results.admin1_name String Full name of the region/state/province. British Columbia
results.city_id Integer Alias for the city primary key, provided for consistency with other endpoints. 5969782
results.continent_id Integer Primary key of the continent record. 2
results.country_id Integer Primary key of the country record. 38
results.country_iso String ISO 3166-1 alpha-2 code of the country. CA
results.country_name String Full name of the country. Canada
results.distance Float Distance from the query point to this city in kilometres, rounded to one decimal place. 3.7
results.id Integer Primary key of the city. 5969782
results.lat String Yes Latitude of the city in decimal degrees. 48.4284
results.lon String Yes Longitude of the city in decimal degrees. -123.3648
results.name String Name of the city. Victoria
results.slug String URL-friendly city name. victoria