簡體   English   中英

如何返回以米為單位的地理距離?

[英]how return distance dbgeography in meter?

在這個例子中,我需要限制搜索來搜索僅僅在10000米左右的地方,這種方法對我來說是行不通的。 這是我的代碼:

  using (GeolocationTestEntities context = new GeolocationTestEntities ())
        {


            var distance = 10000;
            var distanceInMeters = distance * 0.6214;

            var CurrentLocation = DbGeography.FromText("POINT(" + CurrentLat + " " + CurrentLng + ")");
                var places = (from u in context.schoolinfo
                              where u.Location.Distance(CurrentLocation) < distanceInMeters
                              select u).Take(10).Select(x => new schoollinfo() { Name = x.name, Lat = x.Location.Latitude, Lng = x.Location.Longitude, Distance = x.Location.Distance(CurrentLocation) });
                var nearschools = places.ToList();
                HttpCookie cookie = new HttpCookie("Cookie");
                cookie["CurrentLat"] = CurrentLat;
                cookie["CurrentLng"] = CurrentLng;
                this.ControllerContext.HttpContext.Response.Cookies.Add(cookie);

                return Json(nearschools, JsonRequestBehavior.AllowGet);


        }

謝謝,

您不應該使用(距離* 0.6214)。 因為Distance()方法已經使用了米。

暫無
暫無

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

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