簡體   English   中英

如何將dbgeography中的距離返回到km?

[英]how return a distance in dbgeography to km?

這是計算從當前位置到列表中其他地方的距離的 json 結果,但我有一個問題,我無法將距離單位(度)從 dbgeography.location.distance 轉換為 km,這是我的代碼:

 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) }); 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM