1

this is the json result of calculate distance from current position to another placess in the list but i have a issue i can't convert distance unit (degree) to km from dbgeography.location.distance this is my code :

 string CurrentLocation = String.Format("POINT(" + CurrentLat + " " + CurrentLng + ")", 4326);
                DbGeography point = DbGeography.PointFromText(CurrentLocation, DbGeography.DefaultCoordinateSystemId);

                var places = (from u in context.schoolinfo

                              orderby u.Location.Distance(point.Buffer(dist))

                              select u).Take(10).Select(x => new schoollinfo() { Name = x.name, Lat = x.Location.Latitude, Lng = x.Location.Longitude, Distance = x.Location.Distance(point.Buffer(dist)) }); ;

                var nearschools = places.ToList();
                return Json(nearschools, JsonRequestBehavior.AllowGet);

Print screen of result

oussama_tr
  • 61
  • 7
  • Does https://earthscience.stackexchange.com/questions/7350/converting-grid-resolution-from-degrees-to-kilometers or https://stackoverflow.com/questions/13934169/system-data-spatial-dbgeography-distance-units help? – mjwills Oct 21 '17 at 22:13
  • @mjwills the first link it s interessant but it's still hard .. – oussama_tr Oct 21 '17 at 22:27

1 Answers1

1

for calaculate a distance it's POINT(LONGITUDE LATITUDE) not POINT(LATITUDE LONGITUDE )so the code will change as this :

     select u).Take(10).Select(x => new schoollinfo() { Name = x.name, Lat = x.Location.Latitude, Lng = x.Location.Longitude, Distance = DbGeography.FromText("POINT(" + x.Location.Longitude + " " + x.Location.Latitude + ")", 4326).Distance(point) }); 
oussama_tr
  • 61
  • 7