Exemple #1
0
        private async void Map_MapClicked(object sender, MapClickedEventArgs e)
        {
            if (CrossGeolocator.Current.IsListening)
            {
                await CrossGeolocator.Current.StopListeningAsync();
            }
            Xamarin.Forms.GoogleMaps.Polyline polyline = null;
            await Task.Run(async() =>
            {
                Plugin.Geolocator.Abstractions.Position position = await CrossGeolocator.Current.GetLastKnownLocationAsync();
                List <Location> locations = Mapmanager.GetPoint(position.Latitude, position.Longitude, e.Point.Latitude, e.Point.Longitude);
                polyline = new Xamarin.Forms.GoogleMaps.Polyline();

                foreach (var location in locations)
                {
                    polyline.Positions.Add(new Position(location.Latitude, location.Longitude));
                }
                polyline.StrokeColor = Color.Blue;
                polyline.StrokeWidth = 5f;
                map.Polylines.Clear();
                Device.BeginInvokeOnMainThread(async() =>
                {
                    map.Polylines.Add(polyline);
                });
                if (!CrossGeolocator.Current.IsListening)
                {
                    isRefreshPolylines = true;
                    await CrossGeolocator.Current.StartListeningAsync(TimeSpan.FromSeconds(1), 1, true);
                }
            });
        }
Exemple #2
0
        private async void Init()
        {
            CrossGeolocator.Current.PositionChanged += GpsTrecking;
            Plugin.Geolocator.Abstractions.Position position = await CrossGeolocator.Current.GetLastKnownLocationAsync();

            if (position != null)
            {
                map.InitialCameraUpdate = CameraUpdateFactory.NewCameraPosition(new CameraPosition(new Position(position.Latitude, position.Longitude), 20, commpas, 50));
            }
            isCompas = true;
        }
Exemple #3
0
        private async void ReadingChanged(object sender, CompassChangedEventArgs e)
        {
            if (e.Reading.HeadingMagneticNorth - commpas > 2 || e.Reading.HeadingMagneticNorth - commpas < -2)
            {
                isMove  = true;
                commpas = e.Reading.HeadingMagneticNorth;
                if (isCompas)
                {
                    Plugin.Geolocator.Abstractions.Position position = await CrossGeolocator.Current.GetLastKnownLocationAsync();

                    if (position != null)
                    {
                        await map.AnimateCamera(CameraUpdateFactory.NewCameraPosition(new CameraPosition(new Position(position.Latitude, position.Longitude), 20, e.Reading.HeadingMagneticNorth, 70)), TimeSpan.FromMilliseconds(10));
                    }
                }
            }
            else
            {
                isMove = false;
            }
        }