如何将 GeoWithin 与 mongodb C# 驱动程序 2.4 一起使用
How Use GeoWithin with mongodb C# Driver 2.4
获取用户位置后,需要使用GeoWithin找到接近用户的点,之前有没有用过body?
顺便说一下,这是 near
和 GeoWithin
的示例:
var point = GeoJson.Point(GeoJson.Geographic(-73.97, 40.77));
var filter = Builders<BsonDocument>.Filter.Near("location", point, 10);
var a = collection.Find(filter1).Any();
var filter2 = Builders<BsonDocument>.Filter.GeoWithin("location", point);
var b = collection.Find(filter2).Any();
您还可以使用 GeoWithinPolygon
和 GeoWithinCenter
。
double[,] polygon = new double[,] { { -73.97, 40.77 }, { -73.9928, 40.7193 }, { -73.9375, 40.8303 }, { -73.97, 40.77 } };
var filter3 = Builders<BsonDocument>.Filter.GeoWithinPolygon("location", polygon);
var c = collection.Find(filter3).Any();
var filter4 = Builders<BsonDocument>.Filter.GeoWithinCenter("location", -73.97, 40.77, 10);
var d = collection.Find(filter4).Any();
希望对您有所帮助。
获取用户位置后,需要使用GeoWithin找到接近用户的点,之前有没有用过body?
顺便说一下,这是 near
和 GeoWithin
的示例:
var point = GeoJson.Point(GeoJson.Geographic(-73.97, 40.77));
var filter = Builders<BsonDocument>.Filter.Near("location", point, 10);
var a = collection.Find(filter1).Any();
var filter2 = Builders<BsonDocument>.Filter.GeoWithin("location", point);
var b = collection.Find(filter2).Any();
您还可以使用 GeoWithinPolygon
和 GeoWithinCenter
。
double[,] polygon = new double[,] { { -73.97, 40.77 }, { -73.9928, 40.7193 }, { -73.9375, 40.8303 }, { -73.97, 40.77 } };
var filter3 = Builders<BsonDocument>.Filter.GeoWithinPolygon("location", polygon);
var c = collection.Find(filter3).Any();
var filter4 = Builders<BsonDocument>.Filter.GeoWithinCenter("location", -73.97, 40.77, 10);
var d = collection.Find(filter4).Any();
希望对您有所帮助。