예제 #1
0
        private async Task <CurrentPosition> GetPosition()
        {
            CurrentPosition p = new CurrentPosition();

            if (CrossGeolocator.Current.IsGeolocationAvailable)
            {
                if (CrossGeolocator.Current.IsGeolocationEnabled)
                {
                    var locator = CrossGeolocator.Current;
                    locator.DesiredAccuracy = 50;

                    var position = await locator.GetPositionAsync(TimeSpan.FromSeconds(10));

                    p.Latitude  = position.Latitude;
                    p.Longitude = position.Longitude;
                }
                else
                {
                    await DisplayAlert("Message", "GPS Not Enabled", "Ok");
                }
            }
            else
            {
                await DisplayAlert("Message", "GPS Not Available", "Ok");
            }
            return(p);
        }
예제 #2
0
        private async void MoveToCurrentLocation()
        {
            CurrentPosition position = await GetPosition();

            Position mapPosition = new Position(position.Latitude, position.Longitude);

            Device.BeginInvokeOnMainThread(() => {
                formMap.MoveToRegion(MapSpan.FromCenterAndRadius(mapPosition, Distance.FromMiles(3)));

                var mapPin = new Pin
                {
                    Type     = PinType.Place,
                    Position = mapPosition,
                    Label    = "Subrata",
                    Address  = "South Dumdum"
                };

                formMap.Pins.Add(mapPin);
            });
        }