【发布时间】:2018-04-02 03:12:50
【问题描述】:
在这个例子中,我需要将搜索限制在例如 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);
}
谢谢,
【问题讨论】:
-
尝试不同的坐标。 DBGeography 中有哪些记录?当前位置是否有纬度/经度?没有这些信息,我们只能猜测......而且你实际上忘了问一个问题。以前有效吗?您遵循什么指南?
-
嗨,我记录了一个纬度/经度的列表,我的问题是我如何只搜索一轮 10 公里的地方,例如,开始位置是当前位置
-
请edit您的问题提供更多信息。谢谢。
标签: c# google-maps asp.net-mvc-5 spatial geographic-distance