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); } }
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); }
protected override void PlatformSpecificStart(MvxLocationOptions options) { if (_locationHandler == null) { _locationHandler = new FusedLocationHandler(this, Context); } _locationHandler.Start(options); }
protected override ValueTask PlatformSpecificStart(MvxLocationOptions options) { if (_locationHandler == null) { _locationHandler = new FusedLocationHandler(this, Context); } return(new ValueTask(_locationHandler.StartAsync(options))); }
//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); }
public void Start(MvxLocationOptions options) { if (_client == null) { EnsureGooglePlayServiceAvailable(_context); Initialize(_context); } _request = CreateLocationRequest(options); _client.Connect(); }
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(); } }
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(); } }
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); }
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; }
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; }
/// <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); }
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(); }
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); }
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; }
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; }
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); }
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); } }
public void StartLocationWatcher(MvxLocationOptions options) { _watcher.Start(options, OnLocation, OnError); }
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(); }