geoNear返回的距离不正确 [英] geoNear returns incorrect distance

查看:57
本文介绍了geoNear返回的距离不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Java中的mongodb地理功能,并且遇到以下问题,运行命令'geoNear':

I'm playing with geo features of mongodb in Java and i'm facing to the following problem running command 'geoNear':

给出:

  • 一个带有GeoJSON对象的名为"GEOENTITIES"的集合
  • 使用Java代码(使用Jongo)对该集合进行索引:

  • A collection named 'GEOENTITIES' with GeoJSON objects
  • This collection is indexed with the Java code (using Jongo):

collection.ensureIndex("{ coordinates : '2dsphere' }");

  • 存在一个坐标为[48.0,9.0]的文档(示例中名为"A")

  • A document (named 'A' for the example) exists with coordinates equals to [48.0, 9.0]

    执行时:

    {geoNear: 'GEOENTITIES', near: [48.0,9.1], spherical: true, num: 5, distanceMultiplier: 6371}
    

    然后:

    我得到命令结果:

    { "dis" : 11.11949328574724 , "obj" : { "coordinates" : [ 48.0 , 9.0] , "_id" : { "$oid" : "51a62a5485878b1ceca38ab3"} , "name" : "Toto"}}
    

    为什么距离为11.11(公里),而根据 http://williams.best计算得出的距离.vwh.net/gccalc.htm -例如-是7.46吗?我认为我做错了什么,但看不到,也许经过更多实验的人可以帮忙?

    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?

    推荐答案

    交换坐标.您需要(纬度,经度):

    Swap your coordinates. You need (long, lat):

    在MongoDB 2.4中,类地球的默认基准是WGS84.坐标轴顺序是经度,纬度.

    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/

    这篇关于geoNear返回的距离不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆