public CadastroOcorrenciaViewModel() { carregarImage = new MvxCommand(ExecutarCarregamentoImagem); var locationWatcher = Mvx.Resolve<IMvxLocationWatcher>(); var options = new MvxLocationOptions { MovementThresholdInM = 50, TimeBetweenUpdates = TimeSpan.FromSeconds(5) }; locationWatcher.Start(options, (location) => { //locationWatcher.Stop(); //Debug.WriteLine(location.Coordinates.Latitude + " : " + location.Coordinates.Longitude); Debug.WriteLine(location.Coordinates.Latitude + " : " + location.Coordinates.Longitude); ReverseGeoLoc reverse = new ReverseGeoLoc(); ReverseGeoLoc.Address_Components reverse1 = new ReverseGeoLoc.Address_Components(); var request = WebRequest.Create("http://maps.google.com/maps/api/geocode/json?latlng=" + location.Coordinates.Latitude + "," + location.Coordinates.Longitude + "&sensor=false") as HttpWebRequest; reverse1 = reverse.DeserializeReverse(request.ToString()); Hello = reverse1.short_name; }, (error) => { Debug.WriteLine(error.Code); }); //locationWatcher.CurrentLocation.Timestamp.DateTime - DateTime.Now; }
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 Start(MvxLocationOptions options, Action <MvxGeoLocation> success, Action <MvxLocationError> error) { lock (this) { _locationCallback = success; _errorCallback = error; PlatformSpecificStart(options); Started = true; } }
public void Start(MvxLocationOptions options, Action<MvxGeoLocation> success, Action<MvxLocationError> error) { lock (this) { _locationCallback = success; _errorCallback = error; PlatformSpecificStart(options); Started = true; } }
protected abstract void PlatformSpecificStart(MvxLocationOptions options);
protected override void PlatformSpecificStart(MvxLocationOptions options) { if (_locationClient != null) throw new MvxException("You cannot start MvxLocation service more than once"); if (GooglePlayServicesUtil.IsGooglePlayServicesAvailable(Context) != ConnectionResult.Success) throw new MvxException("Google Play Services are not available"); _locationRequest = LocationRequest.Create(); _locationRequest.SetInterval((long)options.TimeBetweenUpdates.TotalMilliseconds); _locationRequest.SetSmallestDisplacement(options.MovementThresholdInM); _locationRequest.SetFastestInterval(1000); _locationRequest.SetPriority(options.Accuracy == MvxLocationAccuracy.Fine ? LocationRequest.PriorityHighAccuracy : LocationRequest.PriorityBalancedPowerAccuracy); _locationClient = new LocationClient(Context, _connectionCallBacks, _connectionFailed); _locationClient.Connect(); }