Geospatial with dynamic radius

18 views
Skip to first unread message

John Polling

unread,
May 16, 2011, 9:49:31 AM5/16/11
to MongoMapper
Hi,

A bit of beginners question I'm afraid. I've got this query running
in Mongo just fine

db.users.find({ location : { $within : { $centerSphere : [[x, y],
650/3595] } }, $where : "Geo.sphereDistance( this.location, [x, y] ) <
this.radius" })

This basically allows me to make get users within a set distance, but
to also check their radius meets the relevant x,y so I can filter out
users who have a smaller radius.

I'm a bit stuck as to how to convert that query into a query
mongomapper can read? I've so far got

User.where({ :location => { '$within' => { '$centerSphere' =>
[[52.8444573, -0.435423], 650.to_f/3595.to_f] } }, '$where' =>
"Geo.sphereDistance( this.location, [52.8444573, -0.435423] ) <
70.to_f/3595.to_f" }).all

However I'm getting the following error:

Mongo::OperationFailure: $where compile error

Any help would be greatly appreciated.

John


John Polling

unread,
May 16, 2011, 9:58:37 AM5/16/11
to MongoMapper
got it sorted....it was the .to_f I'd left in the Geo.sphereDistance.
Whoops.



On May 16, 2:49 pm, John Polling <john.pollin...@googlemail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages