MongoDb C#GeoNear查询构建

如何使用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 );