Created
October 16, 2020 01:46
-
-
Save dj-nitehawk/8248e6375d9655a53e10db8aa6bd626f to your computer and use it in GitHub Desktop.
geo search test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using MongoDB.Entities; | |
using System; | |
using System.Threading.Tasks; | |
namespace TestProg | |
{ | |
internal static class Program | |
{ | |
public class ArtGallery : Entity | |
{ | |
public string Name { get; set; } | |
public Coordinates2D Location { get; set; } | |
} | |
private static async Task Main() | |
{ | |
await DB.InitAsync("test"); | |
await new[] | |
{ | |
new ArtGallery { | |
Name = "Galleria Le-Pari", | |
Location = new Coordinates2D(48.8539241, 2.2913515) | |
}, | |
new ArtGallery { | |
Name = "Versailles House Of Art", | |
Location = new Coordinates2D(48.796964, 2.137456) | |
}, | |
new ArtGallery { | |
Name = "Poissy Arts & Crafts", | |
Location = new Coordinates2D(48.928860, 2.046889) | |
} | |
}.SaveAsync(); | |
await DB.Index<ArtGallery>() | |
.Key(g => g.Location, KeyType.Geo2DSphere) | |
.Option(o => o.Background = false) | |
.CreateAsync(); | |
var locEiffelTower = new Coordinates2D(48.857908, 2.295243); | |
var results = await DB.Find<ArtGallery>() | |
.Match(g => g.Location, locEiffelTower, 20000) | |
.ExecuteAsync(); | |
foreach (var gallery in results) | |
{ | |
Console.WriteLine(gallery.Name); | |
} | |
Console.Read(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment