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

Return zero results when no valid coords given.

Fixes issue #75 (ActiveRecord) and more (Mongoid).
parent 642c555d
No related branches found
No related tags found
No related merge requests found
...@@ -36,7 +36,7 @@ module Geocoder::Store ...@@ -36,7 +36,7 @@ module Geocoder::Store
if latitude and longitude if latitude and longitude
near_scope_options(latitude, longitude, *args) near_scope_options(latitude, longitude, *args)
else else
{} where(:id => false) # no results if no lat/lon given
end end
} }
end end
......
...@@ -17,6 +17,10 @@ module Geocoder::Store ...@@ -17,6 +17,10 @@ module Geocoder::Store
scope :near, lambda{ |location, *args| scope :near, lambda{ |location, *args|
coords = Geocoder::Calculations.extract_coordinates(location) coords = Geocoder::Calculations.extract_coordinates(location)
# no results if no lat/lon given
return criteria.where(:id => false) unless coords.is_a?(Array)
radius = args.size > 0 ? args.shift : 20 radius = args.size > 0 ? args.shift : 20
options = args.size > 0 ? args.shift : {} options = args.size > 0 ? args.shift : {}
......
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