Skip to content

Instantly share code, notes, and snippets.

@QVMaster
Forked from tugberkugurlu/DbGeographyTryOut.cs
Created July 24, 2018 14:12
Show Gist options
  • Save QVMaster/218fc44a7ae34b02dce1d4a1d7015693 to your computer and use it in GitHub Desktop.
Save QVMaster/218fc44a7ae34b02dce1d4a1d7015693 to your computer and use it in GitHub Desktop.
System.Data.Spatial.DbGeography sample (Latitude and Longitude).
class Program {
public class Db {
public static Dictionary<string, DbGeography> Locations = new Dictionary<string, DbGeography>() {
//instert the place locations here...
};
}
static void Main(string[] args) {
// POINT(Long Lat)
var myLocation = DbGeography.FromText("POINT(-117.861328 34.089061)");
//Order by distance (nearest one is at the top)
var locations = from location in Db.Locations
orderby location.Value.Distance(myLocation)
select location;
//get the nearest 10 hotels
foreach (var hotelLocation in locations.Take(10)) {
Console.WriteLine(hotelLocation.Key);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment