问题
I'm playing with geo features of mongodb in Java and i'm facing to the following problem running command 'geoNear':
Given:
- A collection named 'GEOENTITIES' with GeoJSON objects
This collection is indexed with the Java code (using Jongo):
collection.ensureIndex("{ coordinates : '2dsphere' }");
A document (named 'A' for the example) exists with coordinates equals to [48.0, 9.0]
When executing :
{geoNear: 'GEOENTITIES', near: [48.0,9.1], spherical: true, num: 5, distanceMultiplier: 6371}
Then:
I have the command result:
{ "dis" : 11.11949328574724 , "obj" : { "coordinates" : [ 48.0 , 9.0] , "_id" : { "$oid" : "51a62a5485878b1ceca38ab3"} , "name" : "Toto"}}
Why the distance is 11.11 (kilometers) whereas the calculated one from http://williams.best.vwh.net/gccalc.htm - for example - is 7.46 ? I think i did something wrong but don't see what, maybe someone more experimented can help?
回答1:
Swap your coordinates. You need (long, lat):
The default datum for an earth-like sphere in MongoDB 2.4 is WGS84. Coordinate-axis order is longitude, latitude.
http://docs.mongodb.org/manual/core/2dsphere/
回答2:
Shame on me, i've found my error... i reversed lat/long in the web site when checking result.
Correct distance is the one given by MongoDB, so everything is ok.
Sorry again, and thanks A. Jesse Jiryu Davis for your help :)
Edit: just see your edited answer, i'll valide it, thanks again.
来源:https://stackoverflow.com/questions/16819231/geonear-returns-incorrect-distance