C# 实现跨平台的指南针(Android和iOS)

C# 实现跨平台的指南针(Android和iOS),c#,xamarin.forms,C#,Xamarin.forms,我想在Xamarin.Forms中实现一个指南针,如下图所示。有什么办法可以实施吗?谢谢 可以为指南针的背景创建图像。用C设置背景图像的旋转。当罗盘读数增加时,您希望旋转逆时针: // "heading" is a double variable that stores the reading of your compass backgroundImage.Rotation = -heading 在旋转背景的顶部,为指针添加另一个图像。在指针顶部,添加两个标签 对于第一个标签,它将显示基本方向

我想在Xamarin.Forms中实现一个指南针,如下图所示。有什么办法可以实施吗?谢谢

可以为指南针的背景创建图像。用C设置背景图像的旋转。当罗盘读数增加时,您希望旋转逆时针:

// "heading" is a double variable that stores the reading of your compass
backgroundImage.Rotation = -heading
在旋转背景的顶部,为指针添加另一个图像。在指针顶部,添加两个标签

对于第一个标签,它将显示基本方向。可以使用以下C代码计算基数方向:

var directions = new string[] { "NE", "SE", "SW", "NW", "NE" };

directionLabel.Text = directions[((int)heading) / 90];
对于第二个标签,它将显示标题。您可以使用以下C代码设置第二个标签的文本:

// assuming variable "heading" is a double
headingLabel.Text = ((int)heading).toString() + "°";
@你有权利! 我已经通过plugin.compass和pcl完成了:-

在旋转背景的顶部,为指针添加另一个图像。在指针顶部,添加两个标签

对于第一个标签,它将显示基本方向。可以使用以下C代码计算基数方向:

var directions = new string[] { "NE", "SE", "SW", "NW", "NE" };

directionLabel.Text = directions[((int)heading) / 90];
字符串[]方向=新字符串[]{N,NE,E,SE,S,SW,W,NW,N}

设计的第一个:-

对于MVVM文件:-

CrossCompass.Current.Start;
 如果CrossCompass.Current.IsSupported
 {

 CrossCompass.Current.CompassChanged+=CompassChangedEvent;

 } 更改公司的事件:-

无效CompassChangedEventobject发送方,CompassChangedEventArgs e
 { 
 GlobalPropertySandMethod.compassDegree=Math.Rounde.Heading.ToString+\u00B0;
 GlobalPropertySeandMethod.compassValue=e.标题;
 _blaffrGoViewModel.CompassDegree=全局属性和方法.CompassDegree;
 GetDirectionWithDegreeMath.RoundGlobalProperty和Method.compassValue;
 _blaffrGoViewModel.Rotation=-GlobalPropertySandMethod.compassValue;
 } 
 在绑定上下文上设置数据:-


public void GetDirectionWithDegreedouble方位角
 {
 尝试
 {
 如果方位角>=0
 {
 CompassDirection=方向[intazimuth/45];
 }
 其他的
 {
 CompassDegree=对不起,指南针不工作。。。。。;
 }
 }
 捕获异常
 {
 Console.WriteLineex.Message;
 }
 }


你好,希瓦姆。在将问题发布到stackoverflow之前,请阅读本节。