如何返回距离dbgeography米?

时间:2017-10-20 21:40:38

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

在这个例子中,我需要限制搜索在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);


        }

感谢,

1 个答案:

答案 0 :(得分:0)

您不应使用(距离* 0.6214)。因为Distance()方法已经使用了米。