【发布时间】:2017-02-14 18:41:04
【问题描述】:
我正在加载并向 Xamarin Forms Map 添加图钉。
使用以下方法获取中心纬度/经度:
public static Position GetCenter(List<Position> geoCoordinates)
{
if (geoCoordinates.Count == 1)
{
return geoCoordinates.Single();
}
double x = 0;
double y = 0;
double z = 0;
foreach (var geoCoordinate in geoCoordinates)
{
var latitude = geoCoordinate.Latitude * Math.PI / 180;
var longitude = geoCoordinate.Longitude * Math.PI / 180;
x += Math.Cos(latitude) * Math.Cos(longitude);
y += Math.Cos(latitude) * Math.Sin(longitude);
z += Math.Sin(latitude);
}
var total = geoCoordinates.Count;
x = x / total;
y = y / total;
z = z / total;
var centralLongitude = Math.Atan2(y, x);
var centralSquareRoot = Math.Sqrt(x * x + y * y);
var centralLatitude = Math.Atan2(z, centralSquareRoot);
var dtoReturn = new Position(centralLatitude * 180 / Math.PI, centralLongitude * 180 / Math.PI);
return dtoReturn;
}
这让我成为了中心:
map.MoveToRegion(MapSpan.FromCenterAndRadius(CENTER, Distance.FromMiles(X));
我的问题是关于Radius 的第二个参数。以英里为单位计算半径的最佳方法是什么?
Distance.FromMiles(X)
【问题讨论】:
-
你有位置的中心,所以对于半径,你不想找到离中心最远的点,然后离开那个点和中心之间的距离吗?您的潜在数据集有多大?
-
嘿@deckertron_9000 这正是我现在正在做的事情!但是,当这些点相距几百英里时,它似乎无法正常工作。不知道是否有更精确的方法。
标签: google-maps xamarin.ios xamarin.forms