Skip to content
Snippets Groups Projects
Commit 6b7114ce authored by Alex Reisner's avatar Alex Reisner
Browse files

Make 'nearbys' instance method accept options hash.

parent 23a8aa0c
Branches
Tags
No related merge requests found
...@@ -131,13 +131,23 @@ module Geocoder ...@@ -131,13 +131,23 @@ module Geocoder
end end
## ##
# Get other geocoded objects within a given radius. # Get other geocoded objects within a given radius (in miles). This method
# The object must be geocoded before this method is called. # calls the +near+ named scope with the object's coordinates as the first
# argument (the object must be geocoded before this method is called).
# #
def nearbys(radius = 20) # You may pass the radius and options arguments as well, but if you
# specify <tt>:conditions</tt> in the options hash you must manually
# omit +self+ from the list of results. You should try to avoid this
# anyway, and use other named scopes to apply further conditions, eg:
#
# venue.nearbys(10).open_on_mondays
# venue.nearbys.with_capacity(2000)
#
def nearbys(radius = 20, options = {})
return [] unless geocoded? return [] unless geocoded?
lat,lon = self.class._get_coordinates(self) coords = self.class._get_coordinates(self)
self.class.near([lat, lon], radius) - [self] options = {:conditions => ["id != ?", id]}.merge(options)
self.class.near(coords, radius, options)
end end
## ##
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment