0

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


        }

谢谢,

4

1 回答 1

0

你不应该使用(距离 * 0.6214)。因为 Distance() 方法已经在使用仪表。

于 2019-08-09T13:34:15.827 回答