ruby on rails - RoR: Check for a location within a radius of the other location, using google maps api -


i using google maps fo rails gem https://github.com/apneadiving/google-maps-for-rails/ . trying find out way through can see if location inside map circle. instance

@circles_json = '[  {"lng": -122.214897, "lat": 37.772323, "radius": 1000000}, ] 

'

this helps me create circle. how see if, lets say, 'location b' inside @circles_json ?

i thinking of using gem ruby geocoderhttp://www.rubygeocoder.com/. if so, how go ahead that? watched railscasts. depends on local db. looking see if 2 location entered in database fall close each other or not. in case, in 50m radius.

any guidance appreciated.

thanks

to check if point within circle, calculate distance between point , circle's center. if distance greater radius, outside circle. if radius greater distance, inside circle.

ruby geocoder has convenient method calculate distance between 2 points.

geocoder::calculations.distance_between(point1, point2) 

to make return true/false, use simple comparator:

in_circle? = geocoder::calculations.distance_between(point1, point2) < radius 

read documentation using #distance_between.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -