如何将dbgeography中的距离返回到km?

时间:2017-10-21 21:59:01

标签: c# json google-maps asp.net-mvc-5 spatial

这是计算列表中当前位置到另一个placess的距离的json结果,但是我有一个问题我无法将距离单位(度)转换为km来自dbgeography.location.distance 这是我的代码:

 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

1 个答案:

答案 0 :(得分:1)

对于calaculate距离它的点(LONGITUDE LATITUDE)不是POINT(LATITUDE LONGITUDE)所以代码会改变为:

 <a href="https://google.com" target="_blank">
<b onclick="location.href='https://example.com';">GO</b></a>