$centerSphere wrong distances

153 views
Skip to first unread message

hukl

unread,
Oct 25, 2010, 10:48:05 AM10/25/10
to mongodb-user
Hey there,


I'm currently experimenting with the new geo sphere feature in 1.7.1.
I'm not sure though how I am supposed to enter a distance / radius in
a $centerSphere query. Is it in km, m, miles, rad ?

I found another post in this group suggesting I should devide lets say
75 meters by the earth radius. This fails but maybe I'm doing
something wrong:

( 75m / 1000 ) / 6371 = 0,000011772092293

I would use that in the query:

db.environments.find({"gps" : {"$within" : {"$centerSphere" :
[[13.396475, 52.510906,], 0,0000117]}}})

This yielded proper results.

Now to check if it works correctly I reduced the radius to see when it
fails to find other coords. I could go as low as 0.000005 which would
correspond to 31 meters. Google maps tells me my points are 75 meters
away. Who is right? What am I doing wrong?

Is mongodb using WGS-84 or a simpler model? Is it meant to be precise?

Kind regards, John

hukl

unread,
Oct 25, 2010, 11:06:52 AM10/25/10
to mongodb-user
I just used the geoNear command with spherical:true to verify the
distances and it returns:

"avgDistance" : 0.0000059047155655745645,
"maxDistance" : 0.000011809431131149129

Where avg distance would be my empirical low value and maxDistance
close enough to the actual distance. Still puzzled.

~ John

Eliot Horowitz

unread,
Oct 27, 2010, 12:57:30 AM10/27/10
to mongod...@googlegroups.com
The 3rd argument should be your distance divided by radius of the earth.
See http://www.mongodb.org/display/DOCS/Geospatial+Indexing#GeospatialIndexing-NewSphericalModel

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>

Reply all
Reply to author
Forward
0 new messages