public void TestSetMaxDistance() { var options = GeoNearOptions.SetMaxDistance(1.5); var expected = "{ 'maxDistance' : 1.5 }".Replace("'", "\""); Assert.AreEqual(expected, options.ToJson()); }
public void TestGeoNear() { database = server.GetDatabase("osm"); var collection = database.GetCollection("map"); var query = Query.EQ("properties.amenity", new BsonString("pub")); // coordinates for the excel centre double lon = 51.5060089; double lat = 0.0371037; var earthRadius = 6378.0; // km var rangeInKm = 3000.0; // km var options = GeoNearOptions .SetMaxDistance(rangeInKm / earthRadius /* to radians */) .SetSpherical(true); var results = collection.GeoNear(query, lat, lon, 10, options); Assert.AreEqual(10, results.Hits.Count); }
static void Main(string[] args) { var client = new MongoClient(connectionString); var server = client.GetServer(); var database = server.GetDatabase("osm"); var collection = database.GetCollection("map"); var query = Query.EQ("properties.amenity", new BsonString("pub")); double lon = 51.5060089; double lat = 0.0371037; var earthRadius = 6378.0; // km var rangeInKm = 3000.0; // km var options = GeoNearOptions .SetMaxDistance(rangeInKm / earthRadius /* to radians */) .SetSpherical(true); var results = collection.GeoNear(query, lat, lon, 10, options); foreach (var result in results.Hits) { try { var name = result.Document["properties"]["name"]; Console.WriteLine(String.Format("{0}", name )); } catch (Exception e) { } } Console.ReadKey(); }
public IEnumerable <PlaygroundEntity> GetByLocation(float lat, float lng) { var earthRadius = 6378.0; // km var rangeInKm = 10.0; // km GetCollection().EnsureIndex(IndexKeys.GeoSpatial("Loc")); //var near = // Query.GT("ExpiresOn", now); var options = GeoNearOptions .SetMaxDistance(rangeInKm / earthRadius /* to radians */) .SetSpherical(true); GeoNearResult <PlaygroundEntity> results = GetCollection().GeoNear( Query.Null, lng, // note the order lat, // [lng, lat] 200, options ); return(results.Hits.Select(result => result.Document)); }
public static GeoNearOptionsBuilder getGeoNearOption(double rangeInM) { return(GeoNearOptions.SetMaxDistance(rangeInM / earthRadius /* to radians */) .SetSpherical(true).SetDistanceMultiplier(earthRadius)); }