How to get nearby POI
I have a database of points of interest, everyone has 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, but my question is:
for a given LAT / LONG, how can I get from the database / array which POIs are nearby by distance, for example:
You are Here the 0.0 nearest POIs within a 2 km radius are:
- POI A (at 1.1 km)
- POI C (at 1.3 km)
- POI F (at 1.9 km)
I have no idea what I should be looking for to get what I want :-(
Any help is appreciated. thanks
a source to share
I want to know what is the method / name / call to get all neighboring POIs from a given position.
Calculating the great circle distance between two latitude / longitude coordinates is easy with Haversine's formula . You can read on and check out the implementation at Calculate Distance, Alert and More Between Latitude / Longitude Points by Chris Veness.
For a given LAT / LONG, how can I get from the database / array which POIs are nearby in the distance?
If you only have a few POIs, you can simply calculate the great circle distance from your point to each POI. Then just sort the list of results by distance.
However, if you have many POIs, you should use a database with spatial indexing capabilities . MySQL , PostgreSQL and SQL Server 2008 have geospatial features (either natively or through extensions) that include spatial indexing and haversine formula implementation.
a source to share