コード例 #1
0
ファイル: MapPage.xaml.cs プロジェクト: charlenni/Mapsui
        public MapPage(Action <IMapControl> setup, Func <MapView?, MapClickedEventArgs, bool>?c = null)
        {
            InitializeComponent();

            // nullable warning workaround
            var test  = this.mapView ?? throw new InvalidOperationException();
            var test1 = this.info ?? throw new InvalidOperationException();

            mapView !.RotationLock        = false;
            mapView.UnSnapRotationDegrees = 30;
            mapView.ReSnapRotationDegrees = 5;

            mapView.PinClicked += OnPinClicked;
            mapView.MapClicked += OnMapClicked;

            Compass.ReadingChanged += Compass_ReadingChanged;

            mapView.MyLocationLayer.UpdateMyLocation(new Mapsui.UI.Maui.Position());

            mapView.Info += MapView_Info;
            mapView.Renderer.WidgetRenders[typeof(CustomWidget.CustomWidget)] = new CustomWidgetSkiaRenderer();

            Task.Run(StartGPS);

            try
            {
                if (!Compass.IsMonitoring)
                {
                    Compass.Start(SensorSpeed.Default);
                }
            }
            catch (Exception) { }

            setup(mapView);

            Clicker = c;
        }
コード例 #2
0
        void ISensorEventListener.OnSensorChanged(SensorEvent e)
        {
            if (e.Sensor.Name == accelerometer && !lastAccelerometerSet)
            {
                e.Values.CopyTo(lastAccelerometer, 0);
                lastAccelerometerSet = true;
            }
            else if (e.Sensor.Name == magnetometer && !lastMagnetometerSet)
            {
                e.Values.CopyTo(lastMagnetometer, 0);
                lastMagnetometerSet = true;
            }

            if (lastAccelerometerSet && lastMagnetometerSet)
            {
                SensorManager.GetRotationMatrix(r, null, lastAccelerometer, lastMagnetometer);
                SensorManager.GetOrientation(r, orientation);

                if (orientation.Length <= 0)
                {
                    return;
                }

                var azimuthInRadians = orientation[0];
                if (applyLowPassFilter)
                {
                    filter.Add(azimuthInRadians);
                    azimuthInRadians = filter.Average();
                }
                var azimuthInDegress = (Java.Lang.Math.ToDegrees(azimuthInRadians) + 360.0) % 360.0;

                var data = new CompassData(azimuthInDegress);
                Compass.OnChanged(data);
                lastMagnetometerSet  = false;
                lastAccelerometerSet = false;
            }
        }