A
A
Al2019-01-16 00:44:43
Database
Al, 2019-01-16 00:44:43

How to find the nearest city from a list based on current coordinates?

There is a database of cities with coordinates (name, lat, lon).
There is a user's current location (lat, lon).
How to correctly calculate the nearest city from the list based on the user's current location?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2019-01-16
@Sanu0074

postgis.net/docs/manual-1.3/ch03.html#id434832
For example, to find all objects with 100 meters of POINT(1000 1000) the following query would work well:

SELECT * FROM geotable 
  WHERE ST_DWithin(geocolumn, 'POINT(1000 1000)', 100.0);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question