Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Funcion que actualiza los puntos del mapa, comprueba la distancia por coordendas, si esta muy cerca llama a la API de google y lanza aviso si es necesario
        /// </summary>
        /// <returns></returns>
        public async Task <bool> UpdateMarkers()
        {
            try
            {
                VehiclesService _vehServ = new VehiclesService();
                var             vehicles = await _vehServ.GetVehicles();

                this._map.Pins.Clear();

                List <Alerta> alertasbuffer = new List <Alerta>();

                foreach (var vehicle in vehicles)
                {
                    InfoCloseVehicule infoVehicle = new InfoCloseVehicule();

                    if (CalculateDistanceLine(myPosition.Latitude, myPosition.Longitude, vehicle.Object.CurrentPosition.Coordinate.Latitude, vehicle.Object.CurrentPosition.Coordinate.Longitude) < distancePosibleAlert)
                    {
                        infoVehicle = await this.GetInformationCloseVehicle(myPosition.Latitude, myPosition.Longitude, vehicle.Object.CurrentPosition.Coordinate.Latitude, vehicle.Object.CurrentPosition.Coordinate.Longitude);
                    }

                    var pin = new Pin
                    {
                        Type     = PinType.Place,
                        Position = new Position(vehicle.Object.CurrentPosition.Coordinate.Latitude, vehicle.Object.CurrentPosition.Coordinate.Longitude),
                        Label    = vehicle.Object.CurrentPosition.Vehicle.ToString(),
                    };
                    this._map.Pins.Add(pin);


                    bool lanzaraviso = ComprobarDistanciaYCarretera(infoVehicle, new Coordinate(myPosition.Latitude, myPosition.Longitude), new Coordinate(myLastPosition.Latitude, myLastPosition.Longitude), vehicle.Object.CurrentPosition.Coordinate, vehicle.Object.LastPosition.Coordinate);

                    if (lanzaraviso)
                    {
                        alertasbuffer.Add(new Alerta(vehicle.Key, vehicle.Object.CurrentPosition.Vehicle, infoVehicle.distanceText, 0, TextoANumero(infoVehicle.distanceText)));
                    }
                }
                //alertasbuffer.Add(new Alerta("1", new Vehicle(), "300 m", 0, 300));
                //alertasbuffer.Add(new Alerta("2", new Vehicle(), "350 m", 0, 350));
                //alertasbuffer.Add(new Alerta("3", new Vehicle(), "360 m", 0, 360));
                //alertasbuffer.Add(new Alerta("4", new Vehicle(), "300 m", 0, 300));
                //alertasbuffer.Add(new Alerta("5", new Vehicle(), "300 m", 0, 300));
                //alertasbuffer.Add(new Alerta("6", new Vehicle(), "300 m", 0, 300));
                alertas = CompararAlertasGuardadasVsNuevas(alertasbuffer);

                if (alertas.Count > 0)
                {
                    Alertar(alertas);
                }
                else
                {
                    PararAlertar();
                }

                await Task.Delay(5000);

                CenterMap();

                return(true);
            }
            catch (Exception ex)
            {
                CenterMap();
                Debug.WriteLine("UpdateMarkers: " + ex.Message);
                return(true);
            }
        }
Exemplo n.º 4
0
        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();
            }
        }