public async Task <string> SetPositionVehicle(MyPosition position) { var vehicle = await firebase .Child("Vehicle") .Child(App.guid.ToString()) //.WithAuth(App.token) .OnceSingleAsync <MyVehicle>(); if (vehicle != null) { MyPosition aux = vehicle.CurrentPosition; vehicle.Time = position.Time; vehicle.CurrentPosition = position; vehicle.LastPosition = aux; } else { vehicle = new MyVehicle(); vehicle.CurrentPosition = position; vehicle.LastPosition = null; vehicle.Time = position.Time; } await firebase .Child("Vehicle") .Child(App.guid.ToString()) //.WithAuth(App.token) .PutAsync(vehicle); return(App.guid.ToString()); }
public async void AvisarSoyLento(Vehicle vehiculo) { VehiclesService _vehServ = new VehiclesService(); var locator = CrossGeolocator.Current; locator.DesiredAccuracy = 50; var position = await locator.GetPositionAsync(timeoutMilliseconds : 10000); //TODO map e to My position MyPosition aux = new MyPosition() { Coordinate = new Coordinate(position.Latitude, position.Longitude), Speed = position.Speed, Vehicle = vehiculo, Time = Helper.ConvertToTimestamp(DateTime.Now).ToString() }; await _vehServ.SetPositionVehicle(aux); }
public async void AvisarSoyLento(Plugin.Geolocator.Abstractions.Position position) { try { VehiclesService _vehServ = new VehiclesService(); //TODO map e to My position MyPosition aux = new MyPosition() { Coordinate = new Coordinate(position.Latitude, position.Longitude), Speed = position.Speed, Vehicle = Vehicle.Otro, Time = Helper.ConvertToTimestamp(DateTime.Now).ToString() }; this._map.MoveToRegion(new MapSpan(new Position(position.Latitude, position.Longitude), 0.05, 0.05)); await _vehServ.SetPositionVehicle(aux); } catch (Exception ex) { Debug.WriteLine("AvisarSoyLento: " + ex.Message); } }
async Task StartListening() { try { var locator = CrossGeolocator.Current; var position = await locator.GetPositionAsync(timeoutMilliseconds : 10000); this._position = "Lat: " + position.Latitude.ToString() + " Long: " + position.Longitude.ToString(); this._time = position.Timestamp.ToString(); this._heading = position.Heading.ToString(); this._speed = position.Speed.ToString(); this._accuracy = position.Accuracy.ToString(); this._altitude = position.Altitude.ToString(); this._altitudeAccuracy = position.AltitudeAccuracy.ToString(); RaisePropertyChanged("Position"); RaisePropertyChanged("Time"); RaisePropertyChanged("Heading"); RaisePropertyChanged("Speed"); RaisePropertyChanged("Accuracy"); RaisePropertyChanged("Altitude"); RaisePropertyChanged("AltitudeAccuracy"); if (!locator.IsListening) { await locator.StartListeningAsync(500, 1, false); locator.PositionChanged += async(sender, e) => { position = e.Position; VehiclesService _vehServ = new VehiclesService(); //TODO map e to My position MyPosition aux = new MyPosition() { Coordinate = new Coordinate(e.Position.Latitude, e.Position.Longitude), Speed = e.Position.Speed, Vehicle = _vehicle, Time = Helper.ConvertToTimestamp(DateTime.Now).ToString() }; this._map.MoveToRegion(new MapSpan(new Position(position.Latitude, position.Longitude), 0.05, 0.05)); await _vehServ.SetPositionVehicle(aux); this._position = "Lat: " + position.Latitude.ToString() + " Long: " + position.Longitude.ToString(); this._time = position.Timestamp.ToString(); this._heading = position.Heading.ToString(); this._speed = position.Speed.ToString(); this._accuracy = position.Accuracy.ToString(); this._altitude = position.Altitude.ToString(); this._altitudeAccuracy = position.AltitudeAccuracy.ToString(); RaisePropertyChanged("Position"); RaisePropertyChanged("Time"); RaisePropertyChanged("Heading"); RaisePropertyChanged("Speed"); RaisePropertyChanged("Accuracy"); RaisePropertyChanged("Altitude"); RaisePropertyChanged("AltitudeAccuracy"); }; } await Task.Delay(5000); StartListening(); } catch (Exception ex) { Debug.WriteLine("Unable to get location, may need to increase timeout: " + ex.Message); await Task.Delay(5000); StartListening(); } }