1

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?

2 Answers 2

5

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/

4
  • The difference is due to the fact that i added the distance parameter to the command, with earth radius in kilometers. But removing this argument give me the following result: 0.0017453293495129868. So not the same than you, that's interrested, i'll investigate more tomorrow on this. Thanks for your reply.
    – kij
    May 29, 2013 at 20:07
  • Oups sorry, didn't see the distance param in your code. Your result is strange, it should append in kilometers, not in radius, right?
    – kij
    May 29, 2013 at 20:09
  • Ha, just change the second coordinate in the insert for correct value <9.0> instead of <9.1>
    – kij
    May 29, 2013 at 20:10
  • Oh, I misunderstood you - I thought your document's coordinates and your search term had the same coordinates. I'll edit my answer. May 29, 2013 at 20:14
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.