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
Leave a Reply