【问题标题】:Which longitude/latitude adjustments do I need to enlarge my map to the northwest and to the southeast?我需要调整哪些经度/纬度来将我的地图放大到西北和东南?
【发布时间】:2014-11-15 16:40:05
【问题描述】:

这与my earlier question有关

我想在我的地图中添加一个“垫片”,这样极端图钉就不会一半在界内,一半在界外。我在正确的轨道上(没有双关语),但我的逻辑是错误的。我写了这个方法:

// Adapted from Brundritt and Boonaert: https://stackoverflow.com/questions/26937358/can-i-adjust-my-bing-maps-view-locationrect-bounding-box-by-a-small-amount
public static Location GetAShimLocation(IList<Location> locations, bool IsForNorthwestCorner)
{
    const double MAP_CUSHION = 0.1; // Is this a comfortable enough cushion?
    // I don't know why the Lats are 85 instead of 90
    double maxLat = -85;
    double minLat = 85;
    double maxLon = -180;
    double minLon = 180;

    foreach (Location loc in locations)
    {
        if (loc.Latitude > maxLat)
        {
            maxLat = loc.Latitude;
        }

        if (loc.Latitude < minLat)
        {
            minLat = loc.Latitude;
        }

        if (loc.Longitude > maxLon)
        {
            maxLon = loc.Longitude;
        }

        if (loc.Longitude < minLon)
        {
            minLon = loc.Longitude;
        }
    }
    Location retLoc = new Location();
    // I'm not sure this math is right - test it later
    if (IsForNorthwestCorner)
    {
        retLoc.Latitude = maxLat - MAP_CUSHION;
        retLoc.Longitude = maxLon - MAP_CUSHION;
    }
    else // SouthEast corner - stretch a little both directions
    {
        retLoc.Latitude = minLat + MAP_CUSHION;
        retLoc.Longitude = minLon + MAP_CUSHION;
    }
    return retLoc;
}

...然后这样称呼它:

private void ResizeMap()
{         
    App.photosetLocationCollection.Add(
        PhotraxUtils.GetAShimLocation(App.photosetLocationCollection, true));            
    App.photosetLocationCollection.Add(
        PhotraxUtils.GetAShimLocation(App.photosetLocationCollection, false));
    photraxMap.SetView(new LocationRect(App.photosetLocationCollection));
}

...并且它确实改变了地图的大小,而不是将“垫片”位置添加为图钉,而是将地图向上拉一点向北和向西,向南和向东,它似乎在垂直挤压它(缩小纬度范围)并水平拉伸它(增加经度)。

这里我真的需要什么最小值和最大值以及减号和加号的组合?

总结一下:我正在寻找的是将地图从西北角向西北“拉伸”一点,从东南角向东南再一点。

50 点(或更多)事后奖励,奖励给发现这一点的人。

更新

这是在合并 Jan Kukacka 的代码之后,并在垫子上玩耍,直到我找到了正确的地方; YMMV(没有双关语)。

public static Location GetAShimLocation(IList<Location> locations, bool IsForNorthwestCorner)
{
    const double MAP_CUSHION = 1.05; // This seems to be about perfect
    //double maxLat = -85; <= This is what the original (ad[a,o]pted) code was, I don't know why 85 instead of 90, though
    //double minLat = 85;
    double maxLat = -90;
    double minLat = 90;
    double maxLon = -180;
    double minLon = 180;

    foreach (Location loc in locations)
    {
        if (loc.Latitude > maxLat)
        {
            maxLat = loc.Latitude;
        }

        if (loc.Latitude < minLat)
        {
            minLat = loc.Latitude;
        }

        if (loc.Longitude > maxLon)
        {
            maxLon = loc.Longitude;
        }

        if (loc.Longitude < minLon)
        {
            minLon = loc.Longitude;
        }
    }
    Location retLoc = new Location();

    double latDif = Math.Abs(maxLat - minLat);
    double lonDif = Math.Abs(maxLon - minLon);
    // This logic from Jan Kukacka https://stackoverflow.com/questions/26948104/which-longitude-latitude-adjustments-do-i-need-to-enlarge-my-map-to-the-northwes
    if (IsForNorthwestCorner)
    {
        retLoc.Latitude = maxLat - MAP_CUSHION * latDif;
        retLoc.Longitude = maxLon - MAP_CUSHION * lonDif;
    }
    else // SouthEast corner - stretch a little both directions
    {
        retLoc.Latitude = minLat + MAP_CUSHION * latDif;
        retLoc.Longitude = minLon + MAP_CUSHION * lonDif;
    }
    // Edge case insurance
    if (retLoc.Latitude > 90.0)
    {
        retLoc.Latitude = 90.0;
    }
    else if (retLoc.Latitude < -90.0)
    {
        retLoc.Latitude = -90.0;
    }

    if (retLoc.Longitude > 180.0)
    {
        retLoc.Latitude = 180.0;
    }
    else if (retLoc.Longitude < -180.0)
    {
        retLoc.Longitude = -180.0;
    }
    return retLoc;
}

【问题讨论】:

  • :赏金在哪里?你能详细说明一下吗?
  • 你只能在问题搁置了几天后才能设置赏金,所以我还不能设置。但事后,我会(“奖励现有答案”)。所以,如果有一个可行的答案,我会在两天内奖励这个问题,然后在一天后奖励赏金(奖励赏金有一个“冷静期”)。我希望那里有一些熟练的赏金猎人!
  • 为了清楚起见,您希望将图钉移动到不正确的位置,以便它们在视野范围内——显然您无法将地图扩展到 [-180, 90] 之外, [180, -90]。我知道这不是把猫送上月球,正如你所说的那样,所以你正在寻找一种依赖比例的方法来移动针脚,使其完全在视野中?
  • 我不想要伪造的图钉(然后用户会点击它们,然后对我感到失望和/或生气),而是要伪造的位置,一个在西北,一个在东南。是的,这样图钉是完全可见的,而不是部分可见的。

标签: c# geolocation geospatial latitude-longitude bing-maps


【解决方案1】:

我不确定您的地图看起来如何“压扁”,但是您的垫子应该相对大小,例如。地图大小的 10%。试试这样的:

 double latDif = Math.Abs(maxLat - minLat);
 double lonDif = Math.Abs(maxLon - minLon);
 if (IsForNorthwestCorner)
 {
     retLoc.Latitude = maxLat - MAP_CUSHION * latDif;
     retLoc.Longitude = maxLon - MAP_CUSHION * lonDif;
 }
 else // SouthEast corner - stretch a little both directions
 {
     retLoc.Latitude = minLat + MAP_CUSHION * latDif;
     retLoc.Longitude = minLon + MAP_CUSHION * lonDif;
 }

【讨论】:

  • 在此处查看尖叫声:stackoverflow.com/questions/26937358/… 了解我的意思 - 地图的顶部和底部都有“越过栅栏”的图钉
  • 我会在我回家的时候把它捷克出来并测试一下;如果它有效,我很乐意给你赏金(当然,我可能需要调整我的 MapCusion 值)。如果我回到布拉格,我会给你买一品脱 Pilsner Urquell(又名人类的甘露)。
  • 谢谢;将尽快奖励赏金(14 小时);查看我的新代码更新。
【解决方案2】:

赤道处的地球半径 = 6,371 公里。赤道被划分为360度的经度,所以赤道的每一度代表大约111.32公里。从赤道向极点移动,此距离在极点处减小到零。要计算不同纬度的距离,请将其乘以纬度的余弦

3 位小数,0.001 度近似于赤道处 111.32 米 北纬 30 度时 96.41 米 北纬 45 度时 78.71 米 北纬 60 度时 55.66 米 28.82 米,北纬 75 度

这意味着给经度加上一个固定值是错误的。随着点向两极移动,该值将需要减小。

给定起点、初始方位和距离,此公式将计算沿(最短距离)大圆弧行进的目的地点和最终方位。 See解释。 给定您的起点,您可以通过从每个点投影 45 度来找到新位置,

var R = 6371 公里 3,960 英里 以弧度表示的 lat/lng d 以公里/英里为单位

我将 javascript 公式显示为不使用 C#。

JavaScript:公式:(所有角度以弧度表示)

var lat2 = Math.asin(Math.sin(lat1)*Math.cos(d/R) +
                    Math.cos(lat1)*Math.sin(d/R)*Math.cos(brng));
var lng2 = lng1 + Math.atan2(Math.sin(brng)*Math.sin(d/R)*Math.cos(lat1),
                         Math.cos(d/R)-Math.sin(lat1)*Math.sin(lat2));

【讨论】:

  • @davidstrachnan:这不是线性变换的问题,即地图大小吗?我认为您的解决方案不起作用!?
  • @davidstrachnan:我不需要超精确的;基本上我需要知道的是:在我的代码中,我需要在哪里使用 minLat、maxLat、minLon 和 MaxLon;另外,我需要为他们添加或减去我的“垫子”吗?我可以玩弄垫子以确保它足够但不要太多,无论它在世界的哪个地方。再说一遍:这个应用程序不是为了把猫送上月球,只是为了确保只有部分可见的图钉完全可见。
猜你喜欢
  • 1970-01-01
  • 2012-01-21
  • 1970-01-01
  • 2011-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-09
相关资源
最近更新 更多