-1

Let say I have lat/lng of a user X e.g 50.597186, 5.449219 and I have a database which contains users(around 1 million) lat and lng . Now I want to find out the users which is nearby user X for example find all users which is in range of 5 km from the X location. How can I find users in database. Any suggestion? I tried this website to get relation ship between lat/lng and distance but I do not understand it how?

Sunny
  • 14,522
  • 15
  • 84
  • 129
  • you can sort your data in ascending order and after that U can Query the DB to Show with the radius of 5 km from X location – Usman Kurd Oct 31 '13 at 06:27

1 Answers1

1

If you want to do this with PHP, use the haversine formula. It's some tricky trigonometry but works like a charm. Note that negative lon/lat indicates west/south (this convention is not followed universally, check your data to be sure).

If you want to do it all in mysql, you could use haversine, and there is also a syntax to approximate other points in a radius. Take a look at this answer.

Community
  • 1
  • 1
mattexx
  • 6,456
  • 3
  • 36
  • 47