我需要哪些经度/纬度调整才能将地图放大到西北和东南?

这与我之前的问题有关

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

// 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 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  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)); } 

…它确实改变了地图的大小而没有将“垫片”位置添加为图钉,但是它不是将地图拉向北部和西部,而是向南和向东,它似乎是垂直挤压它(减少纬度范围)并水平拉伸(增加经度)。

我最需要的是min和max,minus和plus的组合?

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

对于任何想出这一点的人来说,获得50分(或更高)的事后赏金。

UPDATE

这是在结合Jan Kukacka的代码之后,和我一起玩垫子,直到找到了正确的东西; YMMV(没有双关语意)。

 public static Location GetAShimLocation(IList locations, bool IsForNorthwestCorner) { const double MAP_CUSHION = 1.05; // This seems to be about perfect //double maxLat = -85;  maxLat) { maxLat = loc.Latitude; } if (loc.Latitude  maxLon) { maxLon = loc.Longitude; } if (loc.Longitude  90.0) { retLoc.Latitude = 90.0; } else if (retLoc.Latitude  180.0) { retLoc.Latitude = 180.0; } else if (retLoc.Longitude < -180.0) { retLoc.Longitude = -180.0; } return retLoc; } 

我不确定你的地图是如何“压扁”的,但是你的垫子应该是相对大小的,例如。 地图大小的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; } 

赤道地球半径= 6,371公里。 赤道被划分为360度经度,因此赤道处的每个度数大约为111.32 km。 从赤道移向极点,这个距离在极点处减小到零。计算不同纬度的距离乘以纬度的余弦

3位小数,0.001度近似值,赤道111.32米,30度,96.41米,N / S,45度,78.71米,N / S,60度,55.66米N / S,75度N / S,28.82米

这意味着向经度添加固定值是错误的。 当该点向极点移动时,该值将需要减小。

给定起点,初始方位和距离,该公式将计算沿(最短距离)大圆弧行进的目标点和最终方位。 请参阅解释。 根据您的起点,您可以通过从每个点投射45度来找到新位置,

var R = 6371 km 3,960miles lat / lng in radians d in kms / miles

我将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));