Skip to content

Instantly share code, notes, and snippets.

@gavilanch
Created January 7, 2020 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gavilanch/23d12fa13729c25695a82fdf703f9678 to your computer and use it in GitHub Desktop.
Save gavilanch/23d12fa13729c25695a82fdf703f9678 to your computer and use it in GitHub Desktop.
var geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(srid: 4326);
var myLocation = geometryFactory.CreatePoint(new Coordinate(-69.938951, 18.481188));
using (var context = new ApplicationDbContext())
{
var restaurants = context.Restaurants
.OrderBy(x => x.Location.Distance(myLocation))
.Where(x => x.Location.IsWithinDistance(myLocation, 2000))
.Select(x => new { x.Name, x.City, Distance = x.Location.Distance(myLocation) })
.ToList();
Console.WriteLine("-----------");
foreach (var restaurant in restaurants)
{
Console.WriteLine($"{restaurant.Name} from {restaurant.City} ({restaurant.Distance.ToString("N0")} meters away)");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment