Ruby Geocoder near working unexpectedly

67 views Asked by At

Using Alex Reisner's Ruby Geocoder, I have a model "Spot" which is geocoded using this gem

If I select the first spot into and object:

s = Spot.first

Then try to find all the spots within a 10 mile radius (let's say there should be 12 of them), then i would expect Spot.near(s,10) to return an active record object containing 12 spots. Instead it's just returning something like this every time:

Spot.near(s1,10)
 => {:select=>"spots.*,  AS distance, CAST(DEGREES(ATAN2( RADIANS(spots.longitude - -6.88671972656243), RADIANS(spots.latitude - 55.1729431175342))) + 360 AS decimal) % 360 AS bearing", :conditions=>["spots.latitude BETWEEN 55.028211334423354 AND 55.31767490064505 AND spots.longitude BETWEEN -7.140145500612388 AND -6.633293952512472 AND  <= ?", 10], :order=>"distance ASC"} 

Basically it's returning some SQL but no results.

What's going wrong here? Even if i try something a lot wider, like:

Spot.near([40,0],10000)

I still basically get no results back...

EDIT

I am able to execute the query using this (not pretty) addition...

q = Spot.near(s1,10)
spots = Spot.select(q[:select]).where(q[:conditions]).order(q[:order])
0

There are 0 answers