How Use GeoWithin with mongodb C# Driver 2.4

Viewed 779

I need to use GeoWithin to find nearly point to the user after I take his location, did any body used before?

1 Answers

By the way This is a sample for near and 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();

you can also use GeoWithinPolygon and 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();

Hope it helps.

Related