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 geocoder
http://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
Post a Comment