protected override void PlatformSpecificStart(MvxLocationOptions options)
        {
            if (_locationManager != null)
                throw new MvxException("You cannot start the MvxLocation service more than once");

            _locationManager = (LocationManager)Context.GetSystemService(Context.LocationService);
            if (_locationManager == null)
            {
                MvxTrace.Warning("Location Service Manager unavailable - returned null");
                SendError(MvxLocationErrorCode.ServiceUnavailable);
                return;
            }
            var criteria = new Criteria()
                {
                    Accuracy = options.Accuracy == MvxLocationAccuracy.Fine ? Accuracy.Fine : Accuracy.Coarse,
                };
            _bestProvider = _locationManager.GetBestProvider(criteria, true);
            if (_bestProvider == null)
            {
                MvxTrace.Warning("Location Service Provider unavailable - returned null");
                SendError(MvxLocationErrorCode.ServiceUnavailable);
                return;
            }

            _locationManager.RequestLocationUpdates(
                _bestProvider, 
                (long)options.TimeBetweenUpdates.TotalMilliseconds,
                options.MovementThresholdInM, 
                _locationListener);
        }
        protected override void PlatformSpecificStart(MvxLocationOptions options)
        {
            if (_locationManager != null)
            {
                throw new MvxException("You cannot start the MvxLocation service more than once");
            }

            _locationManager = (LocationManager)Context.GetSystemService(Context.LocationService);
            if (_locationManager == null)
            {
                MvxTrace.Warning("Location Service Manager unavailable - returned null");
                SendError(MvxLocationErrorCode.ServiceUnavailable);
                return;
            }
            var criteria = new Criteria()
            {
                Accuracy = options.Accuracy == MvxLocationAccuracy.Fine ? Accuracy.Fine : Accuracy.Coarse,
            };

            _bestProvider = _locationManager.GetBestProvider(criteria, true);
            if (_bestProvider == null)
            {
                MvxTrace.Warning("Location Service Provider unavailable - returned null");
                SendError(MvxLocationErrorCode.ServiceUnavailable);
                return;
            }

            _locationManager.RequestLocationUpdates(
                _bestProvider,
                (long)options.TimeBetweenUpdates.TotalMilliseconds,
                options.MovementThresholdInM,
                _locationListener);
        }
 public void StartGetCurrentLocation(MvxLocationOptions options, Action <MvxGeoLocation> locationHandler, Action <MvxLocationError> errorHandler)
 {
     if (_locationWatcher != null)
     {
         _locationWatcher.Start(options ?? _locationOptions, locationHandler, errorHandler);
     }
 }
Esempio n. 4
0
        public async Task Start(int refreshMovementMeters = 30, int refreshSeconds = 15, bool foreground = true)
        {
            // Stop if already started
            Pause();

            if (!LocationService.Started)
            {
                MvxLocationOptions options = new MvxLocationOptions();

                options.Accuracy             = MvxLocationAccuracy.Fine;
                options.MovementThresholdInM = refreshMovementMeters;
                options.TimeBetweenUpdates   = TimeSpan.FromSeconds(refreshSeconds);

                if (foreground)
                {
                    options.TrackingMode = MvxLocationTrackingMode.Foreground;
                }
                else
                {
                    options.TrackingMode = MvxLocationTrackingMode.Background;
                }

                if (await GetLocationPermissions())
                {
                    LocationService.Start(options, OnLocationUpdated, OnWatcherError);
                }
            }
        }
        private static LocationRequest CreateLocationRequest(MvxLocationOptions options)
        {
            // NOTE options.TrackingMode is not supported

            var request = LocationRequest.Create();

            switch (options.Accuracy)
            {
            case MvxLocationAccuracy.Fine:
                request.SetPriority(LocationRequest.PriorityHighAccuracy);
                break;

            case MvxLocationAccuracy.Coarse:
                request.SetPriority(LocationRequest.PriorityBalancedPowerAccuracy);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            request.SetInterval((long)options.TimeBetweenUpdates.TotalMilliseconds);
            request.SetSmallestDisplacement(options.MovementThresholdInM);

            return(request);
        }
		protected override void PlatformSpecificStart (MvxLocationOptions options)
		{
			if (_locationHandler == null) {
				_locationHandler = new FusedLocationHandler (this, Context);
			}

			_locationHandler.Start (options);
		}
Esempio n. 7
0
        protected override void PlatformSpecificStart(MvxLocationOptions options)
        {
            if (_locationHandler == null)
            {
                _locationHandler = new FusedLocationHandler(this, Context);
            }

            _locationHandler.Start(options);
        }
Esempio n. 8
0
        protected override ValueTask PlatformSpecificStart(MvxLocationOptions options)
        {
            if (_locationHandler == null)
            {
                _locationHandler = new FusedLocationHandler(this, Context);
            }

            return(new ValueTask(_locationHandler.StartAsync(options)));
        }
Esempio n. 9
0
        //private readonly MvxMessenger _messenger;

        public LocationService(IMvxLocationWatcher watcher, IMvxMessenger messenger)
        {
            _watcher   = watcher;
            _messenger = messenger;
            var options = new MvxLocationOptions
            {
                MovementThresholdInM = 2500
            };

            _watcher.Start(options, OnLocation, OnError);
        }
Esempio n. 10
0
        public void Start(MvxLocationOptions options)
        {
            if (_client == null)
            {
                EnsureGooglePlayServiceAvailable(_context);
                Initialize(_context);
            }

            _request = CreateLocationRequest(options);
            _client.Connect();
        }
Esempio n. 11
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.map_screen);

            _locationWatcher = Mvx.Resolve <IMvxLocationWatcher>();
            var options = new MvxLocationOptions();

            _locationWatcher.Start(options, OnLocationFound, OnLocationNotFound);
        }
        protected override void PlatformSpecificStart(MvxLocationOptions options)
        {
            lock (this)
            {
                if (_locationManager != null)
                {
                    throw new MvxException("You cannot start the MvxLocation service more than once");
                }

                _locationManager          = new CLLocationManager();
                _locationManager.Delegate = new LocationDelegate(this);

                if (options.MovementThresholdInM > 0)
                {
                    _locationManager.DistanceFilter = options.MovementThresholdInM;
                }
                else
                {
                    _locationManager.DistanceFilter = CLLocationDistance.FilterNone;
                }
                _locationManager.DesiredAccuracy = options.Accuracy == MvxLocationAccuracy.Fine ? CLLocation.AccuracyBest : CLLocation.AccuracyKilometer;
                if (options.TimeBetweenUpdates > TimeSpan.Zero)
                {
                    Mvx.Warning("TimeBetweenUpdates specified for MvxLocationOptions - but this is not supported in iOS");
                }


                if (options.TrackingMode == MvxLocationTrackingMode.Background)
                {
                    if (IsIOS8orHigher)
                    {
                        _locationManager.RequestAlwaysAuthorization();
                    }
                    else
                    {
                        Mvx.Warning("MvxLocationTrackingMode.Background is not supported for iOS before 8");
                    }
                }
                else
                {
                    if (IsIOS8orHigher)
                    {
                        _locationManager.RequestWhenInUseAuthorization();
                    }
                }

                if (CLLocationManager.HeadingAvailable)
                {
                    _locationManager.StartUpdatingHeading();
                }

                _locationManager.StartUpdatingLocation();
            }
        }
Esempio n. 13
0
 public void GetCurrentLatLong()
 {
     if (_location.Started)
     {
         return;
     }
     _location.Stop();
     options = new MvxLocationOptions()
     {
         Accuracy     = MvxLocationAccuracy.Fine,
         TrackingMode = MvxLocationTrackingMode.Background
     };
     InitializeLocation(options);
 }
        protected override void PlatformSpecificStart(MvxLocationOptions options)
        {
            lock (this)
            {
                if (_locationManager != null)
                    throw new MvxException("You cannot start the MvxLocation service more than once");

                _locationManager = new CLLocationManager();
                _locationManager.Delegate = new LocationDelegate(this);

                if (options.MovementThresholdInM > 0)
                {
                    _locationManager.DistanceFilter = options.MovementThresholdInM;
                }
                else
                {
                    _locationManager.DistanceFilter = CLLocationDistance.FilterNone;
                }
                _locationManager.DesiredAccuracy = options.Accuracy == MvxLocationAccuracy.Fine ? CLLocation.AccuracyBest : CLLocation.AccuracyKilometer;
                if (options.TimeBetweenUpdates > TimeSpan.Zero)
                {
                    Mvx.Warning("TimeBetweenUpdates specified for MvxLocationOptions - but this is not supported in iOS");
                }


				if (options.TrackingMode == MvxLocationTrackingMode.Background)
				{
					if (IsIOS8orHigher)
					{
						_locationManager.RequestAlwaysAuthorization ();
					}
					else
					{
						Mvx.Warning ("MvxLocationTrackingMode.Background is not supported for iOS before 8");
					}
				}
				else
				{
					if (IsIOS8orHigher)
					{
						_locationManager.RequestWhenInUseAuthorization ();
					}
				}

                if (CLLocationManager.HeadingAvailable)
                    _locationManager.StartUpdatingHeading();

                _locationManager.StartUpdatingLocation();
            }
        }
Esempio n. 15
0
        public LocationService(IMvxLocationWatcher watcher, IMvxMessenger messenger)
        {
            _watcher   = watcher;
            _messenger = messenger;
            var options = new MvxLocationOptions()
            {
                Accuracy             = MvxLocationAccuracy.Fine,
                MovementThresholdInM = 5,
                TrackingMode         = MvxLocationTrackingMode.Foreground
            };

            _watcher.Start(options, OnLocation, OnError);
            OnLocation(_watcher.CurrentLocation);
        }
Esempio n. 16
0
        public async Task StartAsync(MvxLocationOptions options)
        {
            EnsureGooglePlayServiceAvailable(_context);

            if (_client == null)
            {
                _client = LocationServices.GetFusedLocationProviderClient(_context);
            }

            // Create location request.
            _request = CreateLocationRequest(options);

            // Start receiving location updates.
            await _client.RequestLocationUpdatesAsync(_request, this, Looper.MainLooper);
        }
        protected override void PlatformSpecificStart(MvxLocationOptions options)
        {
            if (_geolocator != null)
                throw new MvxException("You cannot start the MvxLocation service more than once");

            _geolocator = new Geolocator
                {
                    DesiredAccuracy = options.Accuracy == MvxLocationAccuracy.Fine ? PositionAccuracy.High : PositionAccuracy.Default,
                    MovementThreshold = options.MovementThresholdInM,
                    ReportInterval = (uint)options.TimeBetweenUpdates.TotalMilliseconds
                };

            _geolocator.StatusChanged += OnStatusChanged;
            _geolocator.PositionChanged += OnPositionChanged;
        }
Esempio n. 18
0
 public LocationService(IMvxMessenger messenger, IMvxLocationWatcher location)
 {
     _messenger        = messenger;
     _location         = location;
     LocationAvailable = false;
     options           = new MvxLocationOptions()
     {
         Accuracy     = MvxLocationAccuracy.Fine,
         TrackingMode = MvxLocationTrackingMode.Background
     };
     if (!_location.Started)
     {
         InitializeLocation(options);
     }
 }
        protected override void PlatformSpecificStart(MvxLocationOptions options)
        {
            if (_geolocator != null)
                throw new MvxException("You cannot start the MvxLocation service more than once");

            _geolocator = new GeoCoordinateWatcher
            {
                MovementThreshold = options.MovementThresholdInM
            };

            _geolocator.TryStart(false, TimeSpan.FromMilliseconds((uint)options.TimeBetweenUpdates.TotalMilliseconds));

            _geolocator.StatusChanged += OnStatusChanged;
            _geolocator.PositionChanged += OnPositionChanged;
        }
Esempio n. 20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LocationService" /> class.
        /// </summary>
        /// <param name="watcher">The watcher.</param>
        /// <param name="messenger">The messenger.</param>
        /// <param name="log">The log.</param>
        public LocationService(IMvxLocationWatcher watcher, IMvxMessenger messenger, ILogger log)
        {
            this._watcher   = watcher;
            this._messenger = messenger;
            this._log       = log;

            var options = new MvxLocationOptions
            {
                Accuracy             = MvxLocationAccuracy.Fine,
                TrackingMode         = MvxLocationTrackingMode.Foreground,
                TimeBetweenUpdates   = TimeSpan.Zero,
                MovementThresholdInM = 0,
            };

            this._watcher.Start(options, this.OnLocation, this.OnError);
        }
Esempio n. 21
0
        public void Start(MvxLocationOptions options)
        {
            if (_client == null)
            {
                EnsureGooglePlayServiceAvailable(_context);
                Initialize(_context);
            }

            if (_client.IsConnected || _client.IsConnecting)
            {
                throw new MvxException("Start has already been called. Please call Stop and try again");
            }

            _request = CreateLocationRequest(options);
            _client.Connect();
        }
Esempio n. 22
0
        public LocationService(IMvxLocationWatcher watcher, IMvxMessenger messenger)
        {
            _watcher         = watcher;
            _messenger       = messenger;
            _locationMessage = new LocationMessage(this);
            _updateLoc_token = _messenger.Subscribe <UpdateLocMessage>(OnUpdateLocMessage);

            var options = new MvxLocationOptions
            {
                Accuracy           = MvxLocationAccuracy.Fine,
                TimeBetweenUpdates = TimeSpan.FromSeconds(2),
                TrackingMode       = MvxLocationTrackingMode.Foreground
            };

            _watcher.Start(options, OnLocation, OnError);
        }
Esempio n. 23
0
        protected override void PlatformSpecificStart(MvxLocationOptions options)
        {
            if (_geolocator != null)
            {
                throw new MvxException("You cannot start the MvxLocation service more than once");
            }

            _geolocator = new GeoCoordinateWatcher
            {
                MovementThreshold = options.MovementThresholdInM
            };

            _geolocator.TryStart(false, TimeSpan.FromMilliseconds((uint)options.TimeBetweenUpdates.TotalMilliseconds));

            _geolocator.StatusChanged   += OnStatusChanged;
            _geolocator.PositionChanged += OnPositionChanged;
        }
Esempio n. 24
0
        protected override void PlatformSpecificStart(MvxLocationOptions options)
        {
            if (_geolocator != null)
            {
                throw new MvxException("You cannot start the MvxLocation service more than once");
            }

            _geolocator = new Geolocator
            {
                DesiredAccuracy   = options.Accuracy == MvxLocationAccuracy.Fine ? PositionAccuracy.High : PositionAccuracy.Default,
                MovementThreshold = options.MovementThresholdInM,
                ReportInterval    = (uint)options.TimeBetweenUpdates.TotalMilliseconds
            };

            _geolocator.StatusChanged   += OnStatusChanged;
            _geolocator.PositionChanged += OnPositionChanged;
        }
Esempio n. 25
0
        public Task <MvxCoordinates> GetLocationAsync(MvxLocationOptions options, bool refresh)
        {
            var tcs = new TaskCompletionSource <MvxCoordinates>();

            if (!refresh && _watcher.LastSeenLocation != null)
            {
                tcs.SetResult(_watcher.LastSeenLocation.Coordinates);
            }
            _watcher.Start(options, location =>
            {
                tcs.SetResult(location.Coordinates);
            }, error =>
            {
                tcs.SetException(new Exception(error.Code.ToString()));
            });

            return(tcs.Task);
        }
Esempio n. 26
0
 public MvxGeoLocation LastLocation()
 {
     if (_watcher.Started)
     {
         return(_watcher.CurrentLocation);
     }
     else
     {
         var options = new MvxLocationOptions()
         {
             Accuracy             = MvxLocationAccuracy.Fine,
             MovementThresholdInM = 5,
             TrackingMode         = MvxLocationTrackingMode.Foreground
         };
         _watcher.Start(options, OnLocation, OnError);
         return(_watcher.CurrentLocation);
     }
 }
        protected override void PlatformSpecificStart(MvxLocationOptions options)
        {
            if (_geoWatcher != null)
                throw new MvxException("You cannot start the MvxLocation service more than once");

            _geoWatcher =
                new GeoCoordinateWatcher(options.Accuracy == MvxLocationAccuracy.Fine
                                             ? GeoPositionAccuracy.High
                                             : GeoPositionAccuracy.Default);

            _geoWatcher.MovementThreshold = options.MovementThresholdInM;
            if (options.TimeBetweenUpdates > TimeSpan.Zero)
            {
                Mvx.Warning("TimeBetweenUpdates specified for MvxLocationOptions - but this is not supported in WindowsPhone");
            }

            _geoWatcher.StatusChanged += OnStatusChanged;
            _geoWatcher.PositionChanged += OnPositionChanged;
            _geoWatcher.Start();
        }
        protected override void PlatformSpecificStart(MvxLocationOptions options)
        {
            if (_geoWatcher != null)
            {
                throw new MvxException("You cannot start the MvxLocation service more than once");
            }

            _geoWatcher =
                new GeoCoordinateWatcher(options.Accuracy == MvxLocationAccuracy.Fine
                                             ? GeoPositionAccuracy.High
                                             : GeoPositionAccuracy.Default);

            _geoWatcher.MovementThreshold = options.MovementThresholdInM;
            if (options.TimeBetweenUpdates > TimeSpan.Zero)
            {
                Mvx.Warning("TimeBetweenUpdates specified for MvxLocationOptions - but this is not supported in WindowsPhone");
            }

            _geoWatcher.StatusChanged   += OnStatusChanged;
            _geoWatcher.PositionChanged += OnPositionChanged;
            _geoWatcher.Start();
        }
        public void Start(MvxLocationOptions options, Action <MvxGeoLocation> success, Action <MvxLocationError> error)
        {
            if (string.IsNullOrWhiteSpace(SensorLocationData))
            {
                throw new ArgumentException("SensorLocationData has not yet been initialized. ");
            }

            if (success == null)
            {
                throw new ArgumentNullException("success");
            }
            _onSuccess = success;

            _onError              = error;
            _isStarted            = true;
            _currentLocationIndex = -1;
            _options              = options ?? new MvxLocationOptions();

            InitializeSensorData(SensorLocationData);

            if (_updateTimer == null)
            {
                _updateTimer = new Timer(arg =>
                {
                    var location     = ComputeCurrentPosition();
                    CurrentLocation  = location;
                    LastSeenLocation = location;
                    _onSuccess.Invoke(location);
                },
                                         null, 0, (int)_options.TimeBetweenUpdates.TotalMilliseconds);
            }
            else
            {
                _updateTimer.Change(0, (int)_options.TimeBetweenUpdates.TotalMilliseconds);
            }
        }
Esempio n. 30
0
 public void StartLocationWatcher(MvxLocationOptions options)
 {
     _watcher.Start(options, OnLocation, OnError);
 }
Esempio n. 31
0
 void InitializeLocation(MvxLocationOptions locationOptions)
 {
     _location.Start(locationOptions, onLocation, onError);
 }
 private LocationManager()
 {
     _locationWatcher = Mvx.Resolve <IMvxLocationWatcher>();
     _locationOptions = new MvxLocationOptions();
     _locationOptions.TrackingMode = MvxLocationTrackingMode.Foreground;
 }
		public void Start (MvxLocationOptions options)
		{
			_request = CreateLocationRequest (options);
			_client.Connect ();
		}
		private static LocationRequest CreateLocationRequest (MvxLocationOptions options)
		{
			// NOTE options.TrackingMode is not supported

			var request = LocationRequest.Create ();

			switch (options.Accuracy) {
			case MvxLocationAccuracy.Fine:
				request.SetPriority (LocationRequest.PriorityHighAccuracy);
				break;
			case MvxLocationAccuracy.Coarse:
				request.SetPriority (LocationRequest.PriorityBalancedPowerAccuracy);
				break;
			default:
				throw new ArgumentOutOfRangeException ();
			}

			request.SetInterval ((long)options.TimeBetweenUpdates.TotalMilliseconds);
			request.SetSmallestDisplacement (options.MovementThresholdInM);

			return request;
		}
 public void Start(MvxLocationOptions options)
 {
     _request = CreateLocationRequest(options);
     _client.Connect();
 }