Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find nearest latitude and longitude points

Tags:

geolocation

An question on latitude and longitude...Probably a silly one.

I have a set of latitude and longitudes for various locations.And, I have the latitude and longitude of the location in which I am in.

Now,I have to find the nearest places from my locations from the set of latitudes and longitudes I have. Is thee any special way of calculating it or it is just mere subtraction and checking the difference?

Could you please throw some light on this?

Thanks, J

like image 596
Abhishek Avatar asked Feb 01 '10 01:02

Abhishek


1 Answers

You can use this SQL. it will select then nearest Lat, Lng from your DB entries.

SELECT id,lat,lng, ((ACOS(SIN(your_lat * PI() / 180) * SIN(lat * PI() / 180) + COS(your_lat * PI() / 180) * COS(lat * PI() / 180) * COS((your_long - lng) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS distance FROM your_table_name HAVING distance <='10' ORDER BY distance ASC LIMIT 0,10

Hope this will help.

like image 159
Pritesh Mahajan Avatar answered Oct 25 '22 06:10

Pritesh Mahajan