I have a database with Points of Interest that all have an address.
I want to know what is the method/name/call to get all nearby POIs from a given position.
I understand that I need to convert all my addresses to LAT / LON coordinates at least, but my question is:
for a given LAT / LONG how do I get from the database/array what POIs are nearby by distance, for example:
You are here 0,0 nearest POIs in a 2km radius are:
I have no idea what should I look into to get what I want :-(
Any help is greatly appreciated. Thank you
I want to know what is the method/name/call to get all nearby POIs from a given position.
Calculating the great-circle distance between two latitude/longitude coordinates is easy with the haversine formula. You may want to read further and check out the implementation at Calculate distance, bearing and more between Latitude/Longitude points by Chris Veness.
For a given LAT / LONG how do I get from the database/array what POIs are nearby by distance?
If you will only have a handful of POIs, you can simply calculate the great-circle distance from your point to each POI. Then simply sort the result list by the distance.
However, if you will be having many POIs, you should consider using a database with spatial indexing capabilities. MySQL, PostgreSQL and SQL Server 2008 all have geo-spatial features (either natively or via extensions), which include spatial indexing and implementations of the haversine formula.