geoNear returns incorrect distance

前提是你 提交于 2021-01-29 04:09:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!