Use PostGIS for do this. You can with PostGIS consult by geographic coordinates using as latitude and longitude, or even through an IP. You can solve issues such as what are the nearest locations of me or what is the shortest distance between two points with these functions.
Examples of queries that can be performed using these functions:
– Distance calculation using GEOGRAPHY (122.2km)
SELECT ST_Distance (‘LINESTRING (-122.33 47,606 0.0 51.5)’ :: geography, ‘POINT (64.15 -21.96)’ :: geography);
– Distance calculation using GEOMETRY (13.3 “degrees”)
SELECT ST_Distance (‘LINESTRING (-122.33 47,606 0.0 51.5)’ :: geometry, ‘POINT (64.15 -21.96)’ :: geometry);
What is PostGIS?
PostGIS is a spatial database extender for PostgreSQL object-relational database. It adds support for geographic objects Allowing location queries to be run in SQL.
How to use?
You must have PostgreSQL installed and you need download and install the PostGIS.
You can see the steps to be performed according to your operating system:
+ More Infos :
Oficial WebSite : http://postgis.net/
Good example using with IP locations : http://tapoueh.org/blog/2013/10/09-ip4r