Beispiel #1
0
        public async void StartLocationUpdates()
        {
            /*var locationCriteria = new Criteria();
             *
             * locationCriteria.Accuracy = Accuracy.NoRequirement;
             * locationCriteria.PowerRequirement = Power.NoRequirement;
             *
             * var locationProvider = LocMgr.GetBestProvider(locationCriteria, true);
             *
             * LocMgr.RequestLocationUpdates(locationProvider, 0, 20, this);*/

            var request  = new Xamarin.Essentials.GeolocationRequest(Xamarin.Essentials.GeolocationAccuracy.Medium, TimeSpan.FromSeconds(5));
            var location = await Xamarin.Essentials.Geolocation.GetLocationAsync(request);

            if (location != null)
            {
                try
                {
                    WebReference.BasicHttpBinding_IService1 MyClient = new WebReference.BasicHttpBinding_IService1();

                    MyClient.SetLatLon(Android.Provider.Settings.Secure.GetString(Application.Context.ContentResolver, Android.Provider.Settings.Secure.AndroidId), userid, location.Latitude.ToString(), location.Longitude.ToString(), "");

                    StopSelf();
                }
                catch (Exception ex)
                {
                    StartLocationUpdates();
                }
                //GetAddress(userid, location.Latitude, location.Longitude);
            }
        }
Beispiel #2
0
        public async Task <Xamarin.Essentials.Location> GetUserLocation()
        {
            var request      = new Xamarin.Essentials.GeolocationRequest(Xamarin.Essentials.GeolocationAccuracy.Best, TimeSpan.FromSeconds(10));
            var userLocation = await Xamarin.Essentials.Geolocation.GetLocationAsync(request);

            return(userLocation);
        }
Beispiel #3
0
        public async void GetLocations(string userid)
        {
            try
            {
                var request  = new Xamarin.Essentials.GeolocationRequest(Xamarin.Essentials.GeolocationAccuracy.Best);
                var location = await Xamarin.Essentials.Geolocation.GetLocationAsync(request);

                if (location != null)
                {
                    GetAddress(userid, location.Latitude, location.Longitude);
                }
            }
            catch (Xamarin.Essentials.FeatureNotSupportedException fnsEx)
            {
                // Handle not supported on device exception
            }
            catch (Xamarin.Essentials.FeatureNotEnabledException fneEx)
            {
                // Handle not enabled on device exception
            }
            catch (Xamarin.Essentials.PermissionException pEx)
            {
                // Handle permission exception
            }
            catch (Exception ex)
            {
                // Unable to get location
            }
        }
Beispiel #4
0
        private async Task MyCenterPosition()
        {
            var request = new Xamarin.Essentials.GeolocationRequest(Xamarin.Essentials.GeolocationAccuracy.High, TimeSpan.FromSeconds(10));

            cts = new CancellationTokenSource();
            var location = await Xamarin.Essentials.Geolocation.GetLocationAsync(request, cts.Token);

            if (location != null)
            {
                var newMap = new MapSpan(new Position(location.Latitude, location.Longitude), 0.01, 0.01);
                Map.MoveToRegion(newMap);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Получение местоположение и выполнение какого-то действия.
        /// </summary>
        private async void GetLocation(Func <Task> action)
        {
            try
            {
                var request = new Xamarin.Essentials.GeolocationRequest(Xamarin.Essentials.GeolocationAccuracy.Medium);

                location = await Xamarin.Essentials.Geolocation.GetLocationAsync(request);

                if (location != null)
                {
                    await action();
                }
                else
                {
                    indicator.IsRunning = false;
                }
            }
            catch (Xamarin.Essentials.FeatureNotSupportedException fnsEx)
            {
                // Handle not supported on device exception
                await DisplayAlert("Ошибка", "Не удается определить местоположение", "OK");
            }
            catch (Xamarin.Essentials.FeatureNotEnabledException fneEx)
            {
                // Handle not enabled on device exception
                await DisplayAlert("Ошибка", "Не удается определить местоположение", "OK");
            }
            catch (Xamarin.Essentials.PermissionException pEx)
            {
                // Handle permission exception
                await DisplayAlert("Ошибка", "Не удается определить местоположение", "OK");
            }
            catch (Exception ex)
            {
                // Unable to get location

                await DisplayAlert("Ошибка", "Не удается определить местоположение " + ex.Message, "OK");
            }
        }
Beispiel #6
0
        public async Task <Location> GetLocation()
        {
            try
            {
                var request = new Xamarin.Essentials.GeolocationRequest(Xamarin.Essentials.GeolocationAccuracy.Best);

                var location = await Xamarin.Essentials.Geolocation.GetLocationAsync(request);

                if (location != null)
                {
                    return new Location {
                               Latitude = location.Latitude, Longitude = location.Longitude
                    }
                }
                ;

                return(null);
            }
            catch (Exception)
            {
                // Unable to get location
                return(null);
            }
        }