node.js - 使用纬度和经度按地理位置查找到附近
问题描述
geoNear: function (lat, lon) { return new Promise((resolve) => { UserLocation.geoNear({type: 'Point', 坐标: [parseFloat(query.lat), parseFloat(query.lon)]}, { distanceField:'dist.calculated',maxDistance:100,球形:true},函数(错误,数据){console.log('错误',错误);解析((错误)?{}:(数据==空) ? {} : 数据) }) }) },
解决方案
让文件喜欢
{
"_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
推荐阅读
- django-rest-framework - 如果请求特定的 url,则更改模型字段
- java - 在我们的应用程序运行时面临 DDL 命令中的问题
- python-3.x - 无法使用 boto3 从 DynamoDB StringSet 中删除项目
- android - Camera2 MediaRecorder 改变 Galaxy S9 的帧速率
- mysql - csvkit mysql导入失败,VARCHAR需要方言mysql的长度
- python-3.x - 如何在 Python 的 Gtk 中通过 OpenCV 绘制图片
- symfony - Encore, Vue, Eslint - 使用最新的 vue-eslint-parser
- python - 如何解决未知属性axisbg
- java - Ιs there a way to use a class as a type of variable of another class with GSON?
- javascript - 使用 JavaScript 将一个数组按另一个数组分组