【问题标题】:geoNear pulling inacurate results in MongoDBgeoNear 在 MongoDB 中提取不准确的结果
【发布时间】:2020-10-21 21:34:12
【问题描述】:

在我的数据库中有 cmets,每个评论都有每个国家的经纬度,但 MongoDB 给出的结果不准确,即我在查询中提供巴西 [经纬度] 作为输入

 db.posts.aggregate([ { "$geoNear": {

         "near": [-69.7145414,-13.6574511 ],
         "spherical": true,
         "distanceField": "distance",
         "num":1000000,
        "query":{"post_id":"5efc430e25a363375860e842",}
     }},
     {
        "$sort":{"distance":1}
     } ])

我得到的结果是

  1. 玻利维亚(距巴西 409.5 公里)
  2. 巴拉圭(距巴西 1293 公里)
  3. 秘鲁(距巴西 1645 公里)
  4. 圭亚那(距巴西 1188 公里)

你可以看到

  • 结果 4 接近而不是结果 2,因此它应该在位置 2 这就是我得到不准确结果的原因。

使用本网站计算的距离: https://www.movable-type.co.uk/scripts/latlong.html

我使用的经纬度如下

"Bolivia" => [
    "latitude" => -16.0705819,
    "longitude" => -72.5931926
],
"Paraguay" => [
    "latitude" => -23.3601858,
    "longitude" => -62.9462413
],
"Peru" => [
    "latitude" => -9.1084506,
    "longitude" => -84.0750546
],
"Guyana" => [
    "latitude" => 4.9392707,
    "longitude" => -63.4541328
],
"Brazil" => [
    "latitude" => -13.6574511,
    "longitude" => -69.7145414
]

这些纬度/经度可通过此链接使用:https://www.google.com/maps/place/Brazil/@-13.6574511,-69.7145414,4z/data=!3m1!4b1!4m5!3m4!1s0x9c59c7ebcc28cf:0x295a1506f2293e63!8m2!3d-14.235004!4d-51.92528

【问题讨论】:

标签: laravel mongodb aggregation-framework geo


【解决方案1】:

我想我知道为什么我的距离/结果不准确,虽然这不是我问题的解决方案,但是现在我知道原因如果有人知道最佳原因或解决方案,那么我正在等待,谢谢

MongoDB 假设地球是完美的球体,并且使用的平均半径为 地球来计算两点之间的距离。但正如你所知,地球 不是球体,而是更多的椭球体,因此距离计算将 在 MongoDB 中并不完美但近似。然而,谷歌使用了一个非常 复杂的公式以获得更好的结果。他们确实有庞大的数据库 地球上不同位置的地球半径。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-27
    • 1970-01-01
    • 1970-01-01
    • 2022-08-08
    • 1970-01-01
    • 2017-03-19
    • 2015-11-18
    相关资源
    最近更新 更多