How to make the sample distances and the id of geo points?

Good afternoon.
There are two tables.
geo
id,name,latitude,longitude

geotmp
id,idtmp,latitude,longitude,tmpdist,tmpid

to search the nearest point of geotmp in geo make

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);


Ie, a request updates the distance in geotmp.
And in the query add the id of the point
Ie add

,tmpid=geo.id
what would not make a second request.
Now in php you do so

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


How can you combine in one request?

Thank you!
March 23rd 20 at 19:41
0 answer

Find more questions by tags GeolocationMySQL