Geo Proximity Search in Large Database

I was creating an application with Geo Proximity Search capability
using PHP as server scripting language and MySQL as Database.

I got the solution that might help you.

If we have certain set of objects having their latitude and longitude, we can find some locations from my database with an specified location along with range/radius in KM we are using MySQL Query. Bellow is the given query where [table] means the storage where my all locations are stored and [latitude], [longitude]  are the specified location with whom we are going to compare.

SELECT [columns] FROM [table] WHERE 1=1 AND 3963.191 * ACOS((SIN(PI
() * [latitude] / 180) * SIN(PI() * [table].latitude / 180)) + (COS(PI
() * [latitude] /180) * cos(PI() * [table].latitude / 180) * COS(PI()
* [table].longitude / 180 - PI() * [longitude] / 180)) ) <= 15

Above calculations will give the objects that are within the 15 KM
area from the searched location’s center.

Advertisements

Leave a Comment

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

WordPress.com Logo

You are commenting using your WordPress.com 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