Answer the question
In order to leave comments, you need to log in
How to select the distance and id of a geopoint?
Good afternoon.
There are two tables.
geo
id,name,latitude,longitude
geotmp
id,idtmp,latitude,longitude,tmpdist,tmpid
to find the nearest point from geotmp to geo do
UPDATE geotmp SET tmpdist=(SELECT (6371 *
acos(cos(RADIANS(geotmp.latitude)) * cos(radians(latitude)) * cos(radians(longitude) - RADIANS(geotmp.longitude)) +
sin(RADIANS(geotmp.latitude)) * sin(radians(latitude)))) AS distance FROM geo HAVING DISTANCE < 0.5 ORDER BY distance ASC LIMIT 1);
,tmpid=geo.id
SELECT *,
(6371 *
acos(
cos(radians(".$latitude.")) *
cos(radians(latitude)) *
cos(radians(longitude) -
radians(".$longitude.")) +
sin(radians(".$latitude.")) *
sin(radians(latitude))))
AS distance FROM geo
HAVING distance <= 1 ORDER BY distance ASC limit 1
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question