Skip to content

Instantly share code, notes, and snippets.

@tugberkugurlu
Created June 4, 2012 19:51
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save tugberkugurlu/2870461 to your computer and use it in GitHub Desktop.
Save tugberkugurlu/2870461 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);
}
}
}
@craiggilchrist
Copy link

Awesome, thanks.

@alexbezhanov
Copy link

Good work, thanks.

@bjarynowski
Copy link

Good example, Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment