sql query to get locations in given radius


SELECT
`id`,
`name`,
ACOS( SIN( RADIANS( `latitude` ) ) * SIN( RADIANS( 32.045101000000000 ) ) + COS( RADIANS( `latitude` ) )
* COS( RADIANS( 32.045101000000000 )) * COS( RADIANS( `longitude` ) - RADIANS( 34.766600000000000 )) ) * 6380 AS `distance`
FROM `hotels`
WHERE
ACOS( SIN( RADIANS( `latitude` ) ) * SIN( RADIANS( 32.045101000000000 ) ) + COS( RADIANS( `latitude` ) )
* COS( RADIANS( 32.045101000000000)) * COS( RADIANS( `longitude` ) - RADIANS( 34.766600000000000 )) ) * 6380 < 100
ORDER BY `distance`

http://spinczyk.net/blog/2009/10/04/radius-search-with-google-maps-and-mysql/

But in Rails  Use this gem:

https://github.com/alexreisner/geocoder

Advertisements

I am Senior Software Engineer. I love reading, writing, sharing,developing, hiking, movies, trips, mountains, brooks, hills etc.

Posted in Gems and plugins, Ruby Little Codes, Ruby on Rails

Leave a Reply

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

StackOverFlow
Categories
Archives
%d bloggers like this: