Example #1
0
        public MainPage(IGpsManager manager, IEventAggregator eventAggregator)
        {
            InitializeComponent();

            var map = new Map
            {
                CRS            = "EPSG:3857",
                Transformation = new MinimalTransformation()
            };

            // map.Limiter.PanLimits = new BoundingBox(new Mapsui.Geometries.Point(45.26, 24.68), new Mapsui.Geometries.Point(60.56, 39.26));
            map.Layers.Add(OpenStreetMap.CreateTileLayer());

            map.Widgets.Add(new ScaleBarWidget(map)
            {
                TextAlignment = Alignment.Center, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Top
            });
            map.Widgets.Add(new ZoomInOutWidget {
                MarginX = 20, MarginY = 40
            });
            mapView.Map = map;

            manager.RequestAccessAndStart(new GpsRequest());
            manager.StartListener(new GpsRequest());

            mapView.Navigator = new Navigator(mapView.Map, (IViewport)mapView.Viewport);

            eventAggregator.GetEvent <GpsDataReceivedEvent>().Subscribe(e =>
            {
                Xamarin.Forms.Device.BeginInvokeOnMainThread(() =>
                {
                    var coords = new Position(e.Position.Latitude, e.Position.Longitude);
                    info.Text  = $"{coords} - D:{(int)e.Heading} S:{Math.Round(e.Speed, 2)}";

                    mapView.MyLocationLayer.UpdateMyLocation(new Position(e.Position.Latitude, e.Position.Longitude));
                    mapView.MyLocationLayer.UpdateMyDirection(e.Heading, mapView.Viewport.Rotation);
                    mapView.MyLocationLayer.UpdateMySpeed(e.Speed);
                });
            });
        }
Example #2
0
        public MapPage(IGpsManager manager, IEventAggregator eventAggregator)
        {
            InitializeComponent();
            mapView.Map = CreateMap();
            manager.RequestAccessAndStart(new GpsRequest()
            {
                Interval = TimeSpan.FromSeconds(5), UseBackground = true
            });

            mapView.Navigator    = new Navigator(mapView.Map, (IViewport)mapView.Viewport);
            this.eventAggregator = eventAggregator;
            eventAggregator.GetEvent <GpsDataReceivedEvent>().Subscribe(e =>
            {
                Xamarin.Forms.Device.BeginInvokeOnMainThread(() =>
                {
                    var coords = new Position(e.Position.Latitude, e.Position.Longitude);
                    info.Text  = $"{coords.ToString()} - D:{(int)e.Heading} S:{Math.Round(e.Speed, 2)}";

                    mapView.MyLocationLayer.UpdateMyLocation(new Position(e.Position.Latitude, e.Position.Longitude));
                    mapView.MyLocationLayer.UpdateMyDirection(e.Heading, mapView.Viewport.Rotation);
                    mapView.MyLocationLayer.UpdateMySpeed(e.Speed);
                });
            });
        }
Example #3
0
        public async void StartGps()
        {
            if (!IsGpsConnected)
            {
                var access = await _gpsManager.RequestAccessAndStart(new GpsRequest()
                {
                    Interval      = TimeSpan.FromSeconds(10),
                    Priority      = GpsPriority.Normal,
                    UseBackground = true
                });

                if (access != AccessState.Available)
                {
                    Log.Event($"Failed to connect GPS: {access}");
                }
                else
                {
                    _gpsAvailable = true;
                    Log.Event($"GPS Connected");
                    State.ResetThrottle();
                    MessagingCenter.Send <IGpsManager>(_gpsManager, Constants.Message.GPS_STATE_CHANGED);
                }
            }
        }