gpt4 book ai didi

c# - 如何查看 xamarin 形式的两个引脚之间的距离并将距离作为字符串获取?

转载 作者:行者123 更新时间:2023-11-30 19:24:24 25 4
gpt4 key购买 nike

我在 map 上有两个带有经度和纬度的图钉,我想知道它们之间的距离。这是我目前所拥有的。

        var myPin = new Pin ();
myPin.Label = "pin1";
myPin.Address = "test1";
myPin.Position = new Position(37.797513, -122.402068);

myPin.Label = "pin2";
myPin.Address = "test2";
myPin.Position = new Position(37.7, -122.3);

mymap.Pins.Add(myPin);

所以我的 map 上有两个不同的图钉。我怎样才能看到这两者之间的距离(以公里为单位)?我的目标是制作一个以距离(公里)作为文本的标签。

(我已经准备好客户渲染器基础,以防解决距离函数的唯一方法是通过渲染器)。

最佳答案

如果你有两个引脚,你有它们的经度和纬度值,那么可以使用下面的代码计算 em 之间的距离(取自 geodatasource.com)

private double distance(double lat1, double lon1, double lat2, double lon2, char unit) {
double theta = lon1 - lon2;
double dist = Math.Sin(deg2rad(lat1)) * Math.Sin(deg2rad(lat2)) + Math.Cos(deg2rad(lat1)) * Math.Cos(deg2rad(lat2)) * Math.Cos(deg2rad(theta));
dist = Math.Acos(dist);
dist = rad2deg(dist);
dist = dist * 60 * 1.1515;
if (unit == 'K') {
dist = dist * 1.609344;
} else if (unit == 'N') {
dist = dist * 0.8684;
}
return (dist);
}

private double deg2rad(double deg) {
return (deg * Math.PI / 180.0);
}

private double rad2deg(double rad) {
return (rad / Math.PI * 180.0);
}

所以基本上你只需要一个纬度/经度值的起始引用,你将从那里引用进一步的引脚以将此距离显示为标签

关于c# - 如何查看 xamarin 形式的两个引脚之间的距离并将距离作为字符串获取?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37446156/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com