Creating DbGeography from Lat Lon

14. June 2013 12:17 by martijn in dbgeography, entity framework

One of the trivial things I missed in EF5 DbGeography is a way to create a DbGeography from lat lon. I created a helper for just that:

 

public static class DbGeographyHelper

{

    public static  DbGeography FromLatLon(double lat,double lon)

    {

        var p1 = string.Format("POINT({0} {1})", lon, lat);

        return DbGeography.FromText(p1);

    }

}

 

 

Enjoy!