Example #1
0
 public void AddLocationListener(ILocationListener listener)
 {
     if (listener != null)
     {
         // remember the listener and start location updates if necessary
         bool needToStartLocator = !locator.IsListening && registeredListeners.Count == 0;
         registeredListeners.Add(listener);
         locator.PositionChanged += listener.LocationChanged;
         if (needToStartLocator)
         {
             locator.StartListeningAsync(AppSharedData.MinTimeBwUpdates, AppSharedData.MinDistanceChangeForUpdates);
         }
     }
 }
 public void Resume()
 {
     if (_crossGeolocator != null)
     {
         _crossGeolocator.StartListeningAsync(minTime: _minimumTime, minDistance: _minimumDistance);
     }
 }
Example #3
0
 public async Task StartAsync()
 {
     _geolocatorService.PositionChanged += GeolocatorServiceOnPositionChanged;
     try
     {
         if (_geolocatorService.IsListening)
         {
             return;
         }
         await _geolocatorService.StartListeningAsync(TimeSpan.FromSeconds(1), 0, false, new ListenerSettings()
         {
             ActivityType                      = ActivityType.Other,
             AllowBackgroundUpdates            = true,
             DeferLocationUpdates              = false,
             ListenForSignificantChanges       = false,
             PauseLocationUpdatesAutomatically = false,
             DeferralDistanceMeters            = 100,
             DeferralTime                      = TimeSpan.FromSeconds(1)
         })
         .ConfigureAwait(false);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
        public override async Task OnAppearing()
        {
            //permissions
            PermissionStatus status = await permissions.CheckPermissionStatusAsync(Permission.Location);

            if (status != PermissionStatus.Granted)
            {
                var permissionsStatus = await permissions.RequestPermissionsAsync(Permission.Location);

                if (permissionsStatus.ContainsKey(Permission.Location) && permissionsStatus[Permission.Location] == PermissionStatus.Granted)
                {
                    await GetPositionAsync();
                }
                else
                {
                    //popup
                    return;
                }
            }
            else
            {
                geolocator.PositionChanged += Geolocator_PositionChanged;
                await geolocator.StartListeningAsync(new TimeSpan(0, 1, 0), 25);
            }
        }
Example #5
0
        private async void GetLocation()
        {
            //var locator = CrossGeolocator.Current;
            position = await geolocator.GetPositionAsync();

            await geolocator.StartListeningAsync(TimeSpan.FromMinutes(30), 500);
        }
Example #6
0
        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
        }
Example #7
0
        async Task <bool> StartTracking()
        {
            geolocator = CrossGeolocator.Current;

            if (!geolocator.IsGeolocationAvailable)
            {
                DisplayAlert("Error", "Location is not awailable", "Ok");
                return(false);
            }

            Position result = null;

            try {
                geolocator.DesiredAccuracy = 50;

                if (!geolocator.IsListening)
                {
                    await geolocator.StartListeningAsync(5, 10);
                }

                oldPosition = await geolocator.GetPositionAsync(50000, CancellationToken.None);

                geolocator.PositionChanged += Geolocator_PositionChanged;
            } catch (Exception ex) {
                System.Diagnostics.Debug.WriteLine("Error : {0}", ex);
                return(false);
            }
            return(true);
        }
Example #8
0
        protected override async void OnAppearing()
        {
            base.OnAppearing();

            if (hasLocationPermission)
            {
                if (CrossGeolocator.IsSupported && CrossGeolocator.Current.IsGeolocationAvailable && CrossGeolocator.Current.IsGeolocationEnabled)
                {
                    locator.PositionChanged += Locator_PositionChanged;
                    await locator.StartListeningAsync(TimeSpan.FromSeconds(0), 50, true);

                    var position = await locator.GetPositionAsync();

                    var center = new Xamarin.Forms.Maps.Position(position.Latitude, position.Longitude);
                    var span   = new Xamarin.Forms.Maps.MapSpan(center, 2, 2);

                    locationsMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Xamarin.Forms.Maps.Position(position.Latitude, position.Longitude),
                                                                          Distance.FromMiles(1)));

                    //using (SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation))
                    //{
                    //    conn.CreateTable<Post>();
                    //    var posts = conn.Table<Post>().ToList();

                    //    DisplayInMap(posts);
                    //}

                    var posts = await Post.Read();

                    DisplayInMap(posts);
                }
            }
        }
Example #9
0
        // added using System.Threading.Tasks;
        public async Task <Position> GetLocation(TimeSpan minimumTime, int minimumMeters)
        {
            position = await locator.GetPositionAsync();

            await locator.StartListeningAsync(minimumTime, minimumMeters);

            return(position);
        }
Example #10
0
        public async Task StartService()
        {
            if (await RequestPermission())
            {
                _geolocator.PositionChanged += GeolocationOnPositionChanged;

                await _geolocator.StartListeningAsync(1000, 10);
            }
        }
Example #11
0
        public PedidosAcompanhamentoPage()
        {
            InitializeComponent();
            locator = CrossGeolocator.Current;
            locator.DesiredAccuracy = 50;

            locator.PositionChanged += OnPositionChanged;
            locator.StartListeningAsync(60000, 50);
        }
        private async void GetLocation()
        {
            position = await locator.GetPositionAsync();

            if (!locator.IsListening)
            {
                await locator.StartListeningAsync(TimeSpan.FromMinutes(30), 500);
            }
        }
Example #13
0
        protected override async void OnAppearing()
        {
            base.OnAppearing();

            locator.PositionChanged += Locator_PositionChanged;
            await locator.StartListeningAsync(TimeSpan.FromSeconds(0), 100);

            GetLocation();
        }
        public async Task StartListening()
        {
            if (locator.IsListening)
            {
                return;
            }

            locator.PositionChanged += Locator_PositionChanged;
            await locator.StartListeningAsync(TimeSpan.FromSeconds(3), 5);
        }
Example #15
0
        public async void StartListening()
        {
            await locator.StartListeningAsync(new TimeSpan(0, 0, 0, 3), 0.0, true, new Plugin.Geolocator.Abstractions.ListenerSettings
            {
                ActivityType           = Plugin.Geolocator.Abstractions.ActivityType.Fitness,
                AllowBackgroundUpdates = true
            });

            locator.PositionChanged += Locator_PositionChanged;
        }
Example #16
0
        public async Task <Position> GetLocation(TimeSpan minimumTime, int minimumMeters)
        {
            position = await locator.GetPositionAsync(); // get current position

            if (!locator.IsListening)
            {
                await locator.StartListeningAsync(minimumTime, minimumMeters);
            }
            return(position);
        }
        public GeolocationService()
        {
            _locator = CrossGeolocator.Current;
            //_locator.AllowsBackgroundUpdates = true;
            _locator.DesiredAccuracy = 50;

            _locator.PositionChanged += OnGeolocatorPositionChanged;

            _locator.StartListeningAsync(2500, 10.0f, true);
        }
Example #18
0
        private async void StartListeningAsync()
        {
            if (geolocatorInstance.IsListening)
            {
                return;
            }

            await geolocatorInstance.StartListeningAsync(TimeSpan.FromSeconds(5), 5);

            geolocatorInstance.PositionChanged += Current_PositionChanged;
        }
Example #19
0
        public async Task StartTracking()
        {
            if (!await _permissionValidator.ValidateGeolocationPermission() || _geolocator.IsListening)
            {
                return;
            }

            await _geolocator.StartListeningAsync(TimeSpan.FromSeconds(2), 0);

            _geolocator.PositionChanged += PositionChanged;
        }
Example #20
0
        /// <summary>
        /// Starts the run.
        /// </summary>
        /// <returns>The run.</returns>
        public async Task StartRun()
        {
            ResetRun();
            IsRunning = true;

            await GetCurrentLocation();

            await m_locator.StartListeningAsync(1000, 0);

            OnRunStarted();
        }
Example #21
0
        public async Task StartListening()
        {
            if (locator.IsListening)
            {
                return;
            }

            await locator.StartListeningAsync(TimeSpan.FromSeconds(5), 10, true);

            locator.PositionChanged += Locator_PositionChanged;
            locator.PositionError   += Locator_PositionError;
        }
        public static async Task StartListeningAsync(this IGeolocator geolocator)
        {
            if (geolocator.IsListening)
            {
                return;
            }

            await geolocator.StartListeningAsync(Configuration.Geolocator.MinimumTime,
                                                 Configuration.Geolocator.MinimumDistance,
                                                 Configuration.Geolocator.IncludeHeading,
                                                 Configuration.Geolocator.ListenerSettings);
        }
Example #23
0
        private async Task StartListeningToLocationAsync()
        {
            if (!_geoLocator.IsListening)
            {
                await _geoLocator.StartListeningAsync(TimeSpan.FromSeconds(2.5), 2, false, new ListenerSettings
                {
                    PauseLocationUpdatesAutomatically = true,
                    DeferLocationUpdates = true
                });
            }

            _geoLocator.PositionChanged += OnLocationUpdate;
        }
        public async Task <bool> StartListeningAsync()
        {
            if (locator.IsListening)
            {
                return(true);
            }

            if (await locator.StartListeningAsync(10000, 500))
            {
                ForceUpdateAsync();
                return(true);
            }
            return(false);
        }
Example #25
0
        protected override async void OnAppearing()
        {
            base.OnAppearing();

            //RouteCoordinates = "{Binding RouteCoordinates}"
            //CustomPins = "{Binding CustomPins}"

            try
            {
                var locationStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location);

                if (locationStatus != PermissionStatus.Granted)
                {
                    if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Location))
                    {
                        await DisplayAlert("Need Permission", "We want to know where you are", "OK");
                    }

                    var locationResult = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Location);

                    if (locationResult.ContainsKey(Permission.Location))
                    {
                        locationStatus = locationResult[Permission.Location];
                    }
                }

                if (locationStatus == PermissionStatus.Granted)
                {
                    if (!_locator.IsListening)
                    {
                        await _locator.StartListeningAsync(new TimeSpan(), 100); // User must move at least 100 meters before event fires
                    }

                    var position = await _locator.GetPositionAsync();

                    await MoveMapToRegion(position);
                }
                else
                {
                    await DisplayAlert("Need Permission", "Don't have location permission.", "OK");
                }
            }
            catch (Exception ex)
            {
                var t = ex;
            }

            //http://maps.googleapis.com/maps/api/directions/json?origin=34.7304,-86.5861&destination=1314+College+Ave+Davenport+IA&key=AIzaSyAVC3Izu_adI7wYdmhEBDyqvK1A8r-iFDQ
        }
Example #26
0
        public async void AddListener(EventHandler <PositionEventArgs> listener, bool includeHeading)
        {
            if (SensusServiceHelper.Get().ObtainPermission(Permission.Location) != PermissionStatus.Granted)
            {
                throw new Exception("Could not access GPS.");
            }

            // if we're already listening, stop listening first so that the locator can be configured with
            // the most recent listening settings below.
            if (ListeningForChanges)
            {
                await _locator.StopListeningAsync();
            }

            // add new listener
            PositionChanged += listener;
            _listenerHeadings.Add(new Tuple <EventHandler <PositionEventArgs>, bool>(listener, includeHeading));

            _locator.DesiredAccuracy = SensusServiceHelper.Get().GpsDesiredAccuracyMeters;

            await _locator.StartListeningAsync(TimeSpan.FromMilliseconds(SensusServiceHelper.Get().GpsMinTimeDelayMS), SensusServiceHelper.Get().GpsMinDistanceDelayMeters, _listenerHeadings.Any(t => t.Item2), GetListenerSettings());

            SensusServiceHelper.Get().Logger.Log("GPS receiver is now listening for changes.", LoggingLevel.Normal, GetType());
        }
Example #27
0
        void SetupGeoLocator()
        {
            if (Geolocator != null)
            {
                return;
            }
            Geolocator = CrossGeolocator.Current;
            Geolocator.DesiredAccuracy = 100;

            Geolocator.PositionChanged += (sender, e) =>
            {
                CurrentPosition = e.Position;
                System.Diagnostics.Debug.WriteLine("PositionChanged {0} {1}", e.Position.Latitude, e.Position.Longitude);
            };

            Geolocator.StartListeningAsync(1, 1, true);
        }
Example #28
0
 private void GetMyLocation()
 {
     Console.WriteLine("Start MyLocation");
     locator = CrossGeolocator.Current;
     if (!locator.IsGeolocationEnabled)
     {
         enableGPS();
     }
     locator.DesiredAccuracy         = 20;
     locator.AllowsBackgroundUpdates = true;
     locator.PositionChanged        += Locator_PositionChanged;
     locator.PositionError          += Locator_PositionError;
     locator.StartListeningAsync(300000, 100, false);             //5 min , 100 meter
     Console.WriteLine("IsGeolocationAvailable {0}", locator.IsGeolocationAvailable);
     Console.WriteLine("IsGeolocationEnabled {0}", locator.IsGeolocationEnabled);
     Console.WriteLine("IsListening {0}", locator.IsListening);
 }
Example #29
0
        private async Task PrepareGeolocationAsync()
        {
            if (_locator.IsListening || !await IsGeolocationAvailableAsync())
            {
                return;
            }

            await _locator.StartListeningAsync(
                TimeSpan.FromSeconds(10),
                50.0,
                true,
                new ListenerSettings
            {
                ActivityType                      = ActivityType.Fitness,
                AllowBackgroundUpdates            = false,
                PauseLocationUpdatesAutomatically = false
            });
        }
Example #30
0
        private async void GetLocation()
        {
            var status = await CheckAndRequestLocationPermission();

            if (status == PermissionStatus.Granted)
            {
                var location = await Geolocation.GetLocationAsync();

                locator.PositionChanged += Locator_PositionChanged;
                if (!locator.IsListening)
                {
                    await locator.StartListeningAsync(new TimeSpan(0, 1, 0), 100);
                }

                locationsMap.IsShowingUser = true;

                CenterMap(location.Latitude, location.Longitude);
            }
        }
Example #31
0
 private void GetMyLocation()
 {
     Console.WriteLine ("Start MyLocation");
     locator = CrossGeolocator.Current;
     if (!locator.IsGeolocationEnabled) {
         enableGPS ();
     }
     locator.DesiredAccuracy = 20;
     locator.AllowsBackgroundUpdates = true;
     locator.PositionChanged+= Locator_PositionChanged;
     locator.PositionError+= Locator_PositionError;
     locator.StartListeningAsync(300000, 100, false); //5 min , 100 meter
     Console.WriteLine ("IsGeolocationAvailable {0}",locator.IsGeolocationAvailable);
     Console.WriteLine ("IsGeolocationEnabled {0}",locator.IsGeolocationEnabled);
     Console.WriteLine ("IsListening {0}",locator.IsListening);
 }