コード例 #1
0
        private void Error(MvxLocationError error)
        {
            var message = new LocationMessage(this, -1, -1, true, error.Code.ToString());

            _watcher.Stop();
            _messenger.Publish(message);
        }
コード例 #2
0
 public void Stop()
 {
     if (_locationWatcher != null)
     {
         _locationWatcher.Stop();
     }
 }
コード例 #3
0
        public void Init()
        {
            if (!locationWatcher.Started)
            {
                locationWatcher.Start(
                    new MvxLocationOptions {
                    Accuracy = MvxLocationAccuracy.Coarse
                },
                    loc =>
                {
                    UserLocation           = loc;
                    const double tolerance = 0.001;
                    if (Math.Abs(loc.Coordinates.Latitude) > tolerance &&
                        Math.Abs(loc.Coordinates.Longitude) > tolerance)
                    {
                        locationWatcher.Stop();
                    }
                },
                    error => { });
            }

            // defaults
            userAge      = 0;
            userId       = string.Empty;
            userGender   = Gender.Unknown;
            userLocation = new MvxGeoLocation
            {
                Coordinates = new MvxCoordinates
                {
                    Latitude  = 0,
                    Longitude = 0,
                    Accuracy  = 0
                }
            };
        }
コード例 #4
0
        public Task <MvxGeoLocation> GetLocation(CancellationTokenSource tokenSource = null)
        {
            var tcs = new TaskCompletionSource <MvxGeoLocation>();

            StopLocationWatcher();
            _locationWatcher.Start(new MvxLocationOptions()
            {
                Accuracy     = MvxLocationAccuracy.Coarse,
                TrackingMode = MvxLocationTrackingMode.Background
            }, location =>
            {
                tcs.TrySetResult(location);
                _locationWatcher.Stop();
            },
                                   error =>
            {
                tcs.TrySetResult(null);
            });

            Task.Run(async() =>
            {
                if (tokenSource != null)
                {
                    await Task.Delay(60000, tokenSource.Token);
                }
                else
                {
                    await Task.Delay(60000);
                }

                if (!tcs.Task.IsCompleted)
                {
                    MvxGeoLocation currLocation = null;
                    try
                    {
                        currLocation = _locationWatcher.CurrentLocation;
                    }
                    catch
                    {
                    }

                    tcs.TrySetResult(currLocation);
                }
            });

            return(tcs.Task);
        }
コード例 #5
0
        private void OnLocationFound(MvxGeoLocation location)
        {
            _locationWatcher.Stop();
            _currentLocation = location;
            MapFragment mapFrag = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map_screen);

            mapFrag.GetMapAsync(this);
        }
コード例 #6
0
 public void onError(MvxLocationError error)
 {
     if (options.Accuracy == MvxLocationAccuracy.Fine && (DateTime.Now - _locationAcquired).TotalSeconds > 30)
     {
         if (_location.Started)
         {
             return;
         }
         _location.Stop();
         options.Accuracy = MvxLocationAccuracy.Coarse;
         InitializeLocation(options);
     }
     if ((DateTime.Now - _locationAcquired).TotalSeconds > 30)
     {
         LocationAvailable = false;
     }
 }
コード例 #7
0
 public void Stop()
 {
     if (!isStarted)
     {
         return;
     }
     isStarted = false;
     watcher.Stop();
 }
コード例 #8
0
        public FirstViewModel(IMvxLocationWatcher locationWatcher)
        {
            _locationWatcher = locationWatcher;

            _locationWatcher.Start(new MvxLocationOptions {
                Accuracy = MvxLocationAccuracy.Fine
            }, OnLocation, OnError);
            _lat = _locationWatcher.CurrentLocation.Coordinates.Latitude;
            _lng = _locationWatcher.CurrentLocation.Coordinates.Longitude;
            _locationWatcher.Stop();
            System.Diagnostics.Debug.WriteLine($"Lat: {Lat} Lng: {Lng}");
        }
コード例 #9
0
        private void StartWatcher()
        {
            Console.WriteLine("StartWatcher");

            _dispatcher.ExecuteOnMainThreadAsync(() =>
            {
                if (_locationWatcher.Started)
                {
                    Console.WriteLine("Watcher already started!");
                    return;
                }

                _locationWatcher.Start(new MvxLocationOptions()
                {
                    Accuracy = MvxLocationAccuracy.Coarse
                },
                                       location =>
                {
                    _locationWatcher.Stop();

                    OnSuccess(new MvxCoordinates()
                    {
                        Latitude  = location.Coordinates.Latitude,
                        Longitude = location.Coordinates.Longitude
                    });
                },
                                       error =>
                {
                    _locationWatcher.Stop();
                    Console.WriteLine(error.Code);
                    OnError(new Exception(error.Code.ToString()));
                });

                Task.Delay(_timeOut).ContinueWith(_ => OnTimeout());
            });
        }
コード例 #10
0
ファイル: GpsService.cs プロジェクト: alexschott/mwf
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    if (_locationWatcher.Started)
                    {
                        _locationWatcher.Stop();
                    }
                }

                _disposed = true;
            }
        }
コード例 #11
0
 public void StopLocationWatcher()
 {
     _watcher.Stop();
 }
コード例 #12
0
 public void Stop()
 {
     _watcher.Stop();
 }
コード例 #13
0
 public void Stop() => _watcher.Stop();