Search code examples
node.jsgeojsonkmlshapefileqgis

How to find city based on current location lat, lng without reverse geocoding?


How to find city based on current location lat, lng without reverse Geo coding ? I tried to save Indian cities data in the form of Geo json but it is of type Multi Polygon. i didn't find any way to convert it to single polygon which is easy to find. if i try to find lat lng inside every polygon it will take lot of time. i want to do it efficiently and faster way.


Solution

  • If you do not want to use an API, you will need to maintain a list of cities and their coordinates yourself. For example, here is a good starting point for such a list: https://www.latlong.net/category/cities-102-15.html

    With the list, take current lat/lng and calculate the distance. Euclidian distance would work well enough for most practical applications. Sort the results starting by smallest and take the first one. This is your nearest city.