public static getdistance (string currlocationlatlong, int kms)
{
try
{
DbGeography searchLocation = DbGeography.FromText(String. Format("POINT({0} {1})", longitude, latitude));
string[] latlng = currlocationlatlong.Split(new char[] { ',' });
decimal mylat = Convert.ToDecimal(latlng[0]. ToString());
decimal mylng = Convert.ToDecimal(latlng[1]. ToString());
var places = (from u in db.Locations
select u).Select(x => new NewBusinessLocationModel
{
ID=x.ID,
Address=x.Address,
Lat=x.Lat,
Lng=x.Lng,
distance=searchLocation. Distance(
DbGeography.FromText("POINT(" + mylng + " " + mylat + ")"))
})
.OrderBy(x=>x.distance)
.Where(x=>x.distance<kms)
.ToList();
return places;
}
catch (Exception ex)
{
}
}