如何使用C#驱动程序和GeoNear
方法查询MongoDB附近的地理点?
以下返回具有错误距离值的点:
var results = myCollection.GeoNear( Query.GT("ExpiresOn", now), // only recent values latitude, longitude, 20 );
我怀疑我应该告诉Mongo查询double [] Location
字段,但我不知道查询语法.
var earthRadius = 6378.0; // km var rangeInKm = 3000.0; // km myCollection.EnsureIndex(IndexKeys.GeoSpatial("Location")); var near = Query.GT("ExpiresOn", now); var options = GeoNearOptions .SetMaxDistance(rangeInKm / earthRadius /* to radians */) .SetSpherical(true); var results = myCollection.GeoNear( near, request.Longitude, // note the order request.Latitude, // [lng, lat] 200, options );