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);
为了计算距离,它是点(经度纬度)而不是点(纬度经度)所以代码将更改为:
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) });
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.