protected override void OnAppearing()
        {
            Device.BeginInvokeOnMainThread(async() =>
            {
                if (_geolocator.IsGeolocationEnabled)
                {
                    _position = await _geolocator.GetLastKnownLocationAsync();
                    if (_position == null)
                    {
                        _position = await _geolocator.GetPositionAsync();
                    }
                    var formsMapPosition = new Xamarin.Forms.Maps.Position(_position.Latitude, _position.Longitude);
                    var mapSpan          = MapSpan.FromCenterAndRadius(formsMapPosition, Distance.FromKilometers(1));
                    _map.MoveToRegion(mapSpan);

                    MyPositionPin = new Pin
                    {
                        Address  = "Mi ubicación",
                        Position = formsMapPosition,
                        Type     = PinType.Generic,
                        Label    = "Mi ubicación"
                    };
                    _map.Pins.Add(MyPositionPin);
                }
                else
                {
                    await DisplayAlert("Un momento", "Debes activar tu GPS para usar la aplicación.", "OK");
                }
            });
        }
예제 #2
0
        public static async Task <Position> GetCurrentPosition()
        {
            IGeolocator locator = CrossGeolocator.Current;

            locator.DesiredAccuracy = Constants.MapDesiredAccuracy;

            Position position = await locator.GetLastKnownLocationAsync();

            if (position != null)
            {
                return(position);
            }

            if (!locator.IsGeolocationAvailable || !locator.IsGeolocationEnabled)
            {
                return(null);
            }

            position = await locator.GetPositionAsync(TimeSpan.FromSeconds(Constants.TimeOutSmall), null, true);

            if (position == null)
            {
                return(null);
            }

            return(position);
        }
예제 #3
0
파일: GeoLocator.cs 프로젝트: Haus4/NeCo
        public async void Listen()
        {
            position = null;

            CurrentState = State.Unknown;
            if (locator.IsListening)
            {
                await locator.StopListeningAsync();
            }

            if (!locator.IsGeolocationEnabled ||
                !locator.IsGeolocationAvailable ||
                !await locator.StartListeningAsync(TimeSpan.FromSeconds(10), 100))
            {
                CurrentState = State.Error;
            }
#if DEBUG // For emulators
            else
            {
                Position _position = await locator.GetLastKnownLocationAsync();

                if (position == null && _position != null)
                {
                    position     = _position;
                    CurrentState = State.Success;
                }
            }
#endif
        }
예제 #4
0
        protected override void OnAppearing()
        {
            Device.BeginInvokeOnMainThread(async() =>
            {
                if (_geolocator.IsGeolocationEnabled)
                {
                    _position = await _geolocator.GetLastKnownLocationAsync();
                    if (_position == null)
                    {
                        _position = await _geolocator.GetPositionAsync();
                    }
                    var formsMapPosition = new Xamarin.Forms.Maps.Position(_position.Latitude, _position.Longitude);
                    var mapSpan          = MapSpan.FromCenterAndRadius(formsMapPosition, Distance.FromKilometers(1.5));
                    _map.MoveToRegion(mapSpan);

                    Incidents = await AdaptatonEndpoint.Instance.GetIncidents();
                    foreach (var incident in Incidents)
                    {
                        _map.Pins.Add(new Pin
                        {
                            Position = new Xamarin.Forms.Maps.Position((double)incident.Latitude,
                                                                       (double)incident.Longitude),
                            Label = incident.Id
                        });
                    }
                }
                else
                {
                    await DisplayAlert("Un momento", "Debes activar tu GPS para usar la aplicación.", "OK");
                }
            });
        }
예제 #5
0
        private void Start <T>(T sender)
        {
            IGeolocator locator = CrossGeolocator.Current;

            locator.DesiredAccuracy = 50; // <- 1. 50mの精度に指定

            var location = locator.GetLastKnownLocationAsync();

            location.Wait();
            var result = location.Result;
        }
예제 #6
0
        public async void RecupererPosition()
        {
            Position position = null;

            try
            {
                IGeolocator localisation = CrossGeolocator.Current;
                localisation.DesiredAccuracy = 100;
                position = await localisation.GetLastKnownLocationAsync();

                if (position != null)
                {
                    Latitude  = position.Latitude;
                    Longitude = position.Longitude;
                    IEnumerable <Address> addresses = await localisation.GetAddressesForPositionAsync(position, null);

                    Address address = addresses.FirstOrDefault();
                    Adresse = address.Thoroughfare + ", " + address.PostalCode + " " + address.Locality;
                }
                else
                {
                    if (!localisation.IsGeolocationAvailable || !localisation.IsGeolocationEnabled)
                    {
                        Console.WriteLine("Erreur !");
                        return;
                    }
                    else
                    {
                        position = await localisation.GetPositionAsync(TimeSpan.FromSeconds(20), null, true);

                        if (position != null)
                        {
                            Latitude  = position.Latitude;
                            Longitude = position.Longitude;
                            IEnumerable <Address> addresses = await localisation.GetAddressesForPositionAsync(position, null);

                            Address address = addresses.FirstOrDefault();
                            Adresse = address.Thoroughfare + ", " + address.PostalCode + " " + address.Locality;
                        }
                        else
                        {
                            Latitude  = 0;
                            Longitude = 0;
                            Adresse   = "Inconnu";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Impossible de récupérer la location: " + ex);
            }
        }
예제 #7
0
        private void Start()
        {
            IGeolocator locator = CrossGeolocator.Current;

            locator.DesiredAccuracy = 50; // <- 1. 50mの精度に指定

            var location = locator.GetLastKnownLocationAsync();

            location.Wait();
            var result = location.Result;

            Text += $"緯度:{result.Latitude} 経度:{result.Longitude}{Environment.NewLine}";
            //MessagingCenter.Send(this, "Start");
        }
예제 #8
0
 public Task <Position> GetLastKnownLocationAsync()
 {
     return(bestGeolocator.GetLastKnownLocationAsync());
 }