PostgreSQL : How to do research using geolocation in PostgreSQL?

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 :

Documentantion :

Good example using with IP locations :

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s