我希望能够在 Windows 8/Store 应用程序中显示 Bing 地图,其中包含一组图钉/航点,缩放设置将显示每个位置,但仅此而已 - IOW,我想要尽可能多的细节,同时仍然显示所有位置/坐标。
我有这个伪代码:
public static int GetMapZoomSettingForCoordinates(List<String> coordinatesList)
{
string furthestNorth = GetFurthestNorth(coordinatesList);
string furthestSouth = GetFurthestSouth(coordinatesList);
string furthestEast = GetFurthestEast(coordinatesList);
string furthestWest = GetFurthestWest(coordinatesList);
int milesBetweenNorthAndSouthExtremes = GetMilesBetween(furthestNorth, furthestSouth);
int milesBetweenEastAndWestExtremes = GetMilesBetween(furthestEast, furthestWest);
int greaterCardinalDistance = Math.Max(milesBetweenNorthAndSouthExtremes, milesBetweenEastAndWestExtremes);
return GetZoomSettingForDistance(greaterCardinalDistance);
}
...但是“症结”(困难的部分)是“milesBetween”功能。是否存在用于计算两个坐标之间的英里数的现有算法?
我确实意识到这是目前以美国为中心的一堆代码(英里与公里);也就是说,目前,按照设计。
更新
这是我的新伪代码(实际编译代码,但未经测试):
public static int GetMapZoomSettingForCoordinates(List<string> coordinatePairsList)
{
List<double> LatsList = new List<double>();
List<double> LongsList = new List<double>();
List<string> tempList = new List<string>();
foreach (string s in coordinatePairsList)
{
tempList.AddRange(s.Split(';'));
double dLat;
double.TryParse(tempList[0], out dLat);
double dLong;
double.TryParse(tempList[0], out dLong);
LatsList.Add(dLat);
LongsList.Add(dLong);
tempList.Clear();
}
double furthestNorth = GetFurthestNorth(LatsList);
double furthestSouth = GetFurthestSouth(LatsList);
double furthestEast = GetFurthestEast(LongsList);
double furthestWest = GetFurthestWest(LongsList);
int milesToDisplay =
HaversineInMiles(furthestWest, furthestNorth, furthestEast, furthestSouth);
return GetZoomSettingForDistance(milesToDisplay);
}
private static double GetFurthestNorth(List<double> longitudesList)
{
double northernmostVal = 0.0;
foreach (double d in longitudesList)
{
if (d > northernmostVal)
{
northernmostVal = d;
}
}
return northernmostVal;
}
...我仍然不知道 GetZoomSettingForDistance() 应该/做什么,虽然...
更新 2
这是“更好”:
public static int GetMapZoomSettingForCoordinates(List<Tuple<double, double>> coordinatePairsList)
{
var LatsList = new List<double>();
var LongsList = new List<double>();
foreach (Tuple<double,double> tupDub in coordinatePairsList)
{
LatsList.Add(tupDub.Item1);
LongsList.Add(tupDub.Item2);
}
double furthestNorth = GetFurthestNorth(LongsList);
double furthestSouth = GetFurthestSouth(LongsList);
double furthestEast = GetFurthestEast(LatsList);
double furthestWest = GetFurthestWest(LatsList);
int milesToDisplay =
HaversineInMiles(furthestWest, furthestNorth, furthestEast, furthestSouth);
return GetZoomSettingForDistance(milesToDisplay);
}
更新 3
我意识到,关于经线和纬线的经线,我的逻辑至少是倒退或错误的。虽然经度子午线确实是垂直线(“绘制”南北,反之亦然),纬度平行线是水平线(“绘制”东到西),沿这些线的点代表基于纬度平行线的南北位置,并根据经度子午线表示东西位置。这在我的脑海中似乎是倒退的,直到我想象线条在(经度)和向上和(纬度)地球上旋转,而不是像土星环那样简单地环绕地球;帮助我正确理解的还有提醒自己,经度子午线的值决定了一个人所处的时区。所以,