【问题标题】:how return distance dbgeography in meter?如何以米为单位返回距离 dbgeography?
【发布时间】: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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-02
    • 2018-02-01
    • 2012-02-08
    相关资源
    最近更新 更多