【问题标题】:MongoDb $near query in using java not giving proper locations使用 java 的 MongoDb $near 查询没有给出正确的位置
【发布时间】:2014-12-26 12:23:36
【问题描述】:

我对 mongodb 中的 $near 有疑问

我必须找出半径周围特定位置的用户。

我有位置[ 18.58528075595879 , 73.73364686965942],我想从250码半径范围内搜索用户。

我有 users 表,其中有 gpsloc 数组。 我在 gpsloc 上放了索引“2d”

db.users.ensureIndex({loc: "2d"})

我正在尝试的查询

{ "gpsloc" : { "$near" : [ 18.58528075595879 , 73.73364686965942] , "$maxDistance" : 228.6} , "height" : "Average" , "hair" : "Brown" , "gender" : "Male"}

maxDistance (distance in meters/km/?) 的作用

【问题讨论】:

    标签: java mongodb geolocation geospatial mongodb-query


    【解决方案1】:

    maxDistance 需要多少(以米/公里/公里为单位的距离?)

    根据docs

    要使用旧坐标指定点,$near 需要二维索引 并具有以下语法:

    {$near:[ <x>, <y> ],$maxDistance:<distance in radians>}
    

    应该为参数提供radians 中的值。

    对于2dsphere 索引,参数接受meters 中的输入。

    【讨论】:

    • 但是如何将250米转换为弧度,我想跟踪250码内的用户。请帮忙。
    • 通过放置 2dsphere 索引我得到以下错误:"$err" : "can't parse query (2dsphere): { $near: [ 18.5874338, 73.7380072 ], $maxDistance: 240.0 }",
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-04
    • 2019-03-07
    • 2018-10-07
    • 2023-03-25
    • 2019-07-07
    • 1970-01-01
    相关资源
    最近更新 更多