我正在尝试根据与当前位置的距离过滤某些位置。我将位置保存在mongodb中,如下所示:
{
"_id" : ObjectId("5c66bb24546c9e0f14a9c76b"),
"geoLocation" : {
"type" : "Point",
"coordinates" : [
23.762865,
90.4282826
]
}
}
现在,当我从当前位置搜索上方位置时,我看到距离显示为 226.98475261562422 。
db.locations.aggregate([
{ "$geoNear": {
"near": {
"type": "Point",
"coordinates": [90.426333, 23.7638519]
},
"distanceField": "distance",
"spherical": true,
"maxDistance": 1000
}}
])
我也使用 MongoDB Asp.Net C#驱动程序尝试了上述查询,它返回了相同的位置,但是我没有得到距离。但是我检查了一下如果我给出 225 作为最大距离,则返回的结果为空。
public async Task<List<Entity>> GeoNearAsync(
Expression<Func<Entity, object>> locationField, double longitude, double latitude, double distance)
{
var point = new GeoJson2DGeographicCoordinates(longitude, latitude);
var geoJsonPoint = new GeoJsonPoint<GeoJson2DGeographicCoordinates>(point);
var nearFilter = Builders<Entity>.Filter.NearSphere(locationField, geoJsonPoint, distance);
var result = await _collection.Find(nearFilter).ToListAsync();
return result;
}
但是当我去Google地图尝试查看这两个位置之间的距离时,它给了我 650 米。
为什么在mongodb和google map中两个位置之间的距离不同?
mongodb查询返回的计算距离是否正确?如果不正确,如何在mongodb中获得行驶距离?