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