【问题标题】:Find to Near by Geo location using Latitude and Longitude使用纬度和经度按地理位置查找到附近
【发布时间】:2019-08-31 18:35:50
【问题描述】:

geoNear:函数(纬度,经度){ 返回新的承诺((解决)=> { UserLocation.geoNear({type: 'Point', 坐标: [parseFloat(query.lat), parseFloat(query.lon)]}, {distanceField:'dist.calculated',maxDistance:100,球面:true},函数(错误,数据){ console.log('错误', 错误); 解决((错误)?{}:(数据==空)?{}:数据) }) }) },

【问题讨论】:

  • 我想在 NodeJS 和 Monggose 中按地理位置和经纬度对 Ner 进行微调
  • 问题不清楚。请添加更多信息并相应地格式化问题。
  • 如何在 NodeJS 和 Mongodb 中按地理位置纬度和经度接近。我必须编写哪个操作查询?

标签: node.js mongodb mongoose


【解决方案1】:

让文档喜欢

{
"_id" : 3,
"name" : "Polo Grounds",
"location": {
  "type" : "Point",
  "coordinates" : [ -73.9375, 40.8303 ]
}
}

您可以使用查询

db.collection.aggregate([
{
 $geoNear: {
    near: { type: "Point", coordinates: [ -73.98142 , 40.71782 ] },
    key: "location",
    distanceField: "dist.calculated"
 }
}
])

更多详情$geoNear

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-26
    • 1970-01-01
    • 1970-01-01
    • 2019-04-21
    • 2017-11-10
    • 2016-10-16
    • 2014-02-12
    • 1970-01-01
    相关资源
    最近更新 更多