Skip to content
Snippets Groups Projects
Commit 060b37be authored by Ryan Dlugosz's avatar Ryan Dlugosz
Browse files

Add documentation for within_bounding_box strategy

parent 335e79b9
No related branches found
No related tags found
No related merge requests found
...@@ -118,6 +118,16 @@ To find objects by location, use the following scopes: ...@@ -118,6 +118,16 @@ To find objects by location, use the following scopes:
Venue.geocoded # venues with coordinates Venue.geocoded # venues with coordinates
Venue.not_geocoded # venues without coordinates Venue.not_geocoded # venues without coordinates
You can also restrict the bounds used in location queries via the <tt>within_bounding_box</tt> scope. This
can have a dramatic effect on query performance, especially when used in conjunction with indexes on the lat,
lng columns.
distance = 20
center_point = [40.71, 100.23]
box = Geocoder::Calculations.bounding_box(center_point, distance)
Venue.near(center_point, distance).within_bounding_box(box, distance) # same results as above, potentially faster
Venue.within_bounding_box(box, distance) # even faster query, but no distance ordering
With geocoded objects you can do things like this: With geocoded objects you can do things like this:
obj.nearbys(30) # other objects within 30 miles obj.nearbys(30) # other objects within 30 miles
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment