Exemplo n.º 1
0
        private async void OnDialogClosed(IDialogResult result)
        {
            if (result.Parameters.ContainsKey("deleted"))
            {
                var deletedHive = result.Parameters.GetValue <Hive>("deleted");


                RemoveHiveFromMap(deletedHive);
            }

            if (result.Parameters.ContainsKey("savedHive"))
            {
                var newHive = result.Parameters.GetValue <Hive>("savedHive");

                _eventAggregator.GetEvent <UpdateHiveListEvent>().Publish(true);

                AddHiveOnMap(newHive);
                Device.StartTimer(TimeSpan.FromMilliseconds(100), () =>
                {
                    MoveToRegionReq.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(newHive.HiveLocation.Latitude,
                                                                                          newHive.HiveLocation.Longitude), Distance.FromKilometers(8)));
                    return(false);
                });
            }
        }
Exemplo n.º 2
0
        public override void OnNavigatedTo(NavigationParameters parameters)
        {
            // Pins = new ObservableCollection<Pin>();
            //String polylines = null;

            MessagingCenter.Subscribe <ViewModelBase, Plugin.Geolocator.Abstractions.Position>(this, "MudancaPosicao",
                                                                                               (sender, arg) =>
            {
                MoveToRegionReq.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(arg.Latitude, arg.Longitude), Distance.FromKilometers(0.3)));
            });
            if (CrossSettings.Current.Contains("ChamadaAceita"))
            {
                Chamada            = CrossSettings.Current.Get <Chamada>("ChamadaAceita");
                Chamada.valorFinal = Chamada.valorPrevisto.ToString();
                TextoValor         = "Previsão R$" + Chamada.valorPrevisto;
                TextoBotaoFinal    = "Cancelar";
                ShowBotaoInicio    = true;
            }
            else if (CrossSettings.Current.Contains("ChamadaEmCorrida"))
            {
                Chamada = CrossSettings.Current.Get <Chamada>("ChamadaEmCorrida");
                CrossSettings.Current.Set("IsTimerOn", true);
                IniciarTimerPosicao();
                TextoBotaoFinal = "Finalizar";
                ShowBotaoInicio = false;
                // TextoValor = Chamada.valorFinal.ToString("C2", new CultureInfo("pt-BR"));
                //MessagingCenter.Subscribe<ViewModelBase, float>(this, "MudancaValor",
                //   (sender, arg) =>
                //   {
                //       ValorFinalView = arg;
                //       TextoValor = arg.ToString("C2", new CultureInfo("pt-BR"));
                //       TextoValor.Replace(".", ",");
                //   });
            }
            else
            {
                return;
            }


            AjustePosicaoMapa();
        }
Exemplo n.º 3
0
        private async Task GotoUserLocation()
        {
            try
            {
                var location = await Geolocation.GetLastKnownLocationAsync();

                if (location == null)
                {
                    location = await Geolocation.GetLocationAsync(new GeolocationRequest()
                    {
                        DesiredAccuracy = GeolocationAccuracy.Low,
                        Timeout         = TimeSpan.FromSeconds(20)
                    });
                }

                MoveToRegionReq.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(location.Latitude,
                                                                                      location.Longitude), Distance.FromKilometers(10)));
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
        }
Exemplo n.º 4
0
        private async void AjustePosicaoMapa()
        {
            List <Position> lista = DecodePolylinePoints(Chamada.polylines);

            Pins.Clear();
            Plugin.Geolocator.Abstractions.Position pos = await GetCurrentPosition();

            if (MotoristaLogado.verDestino.Equals("S"))
            {
                if (CrossSettings.Current.Contains("ChamadaEmCorrida"))
                {
                    Pin localAtualPin = new Pin()
                    {
                        Type        = PinType.Place,
                        Label       = "Atual",
                        Position    = new Position(pos.Latitude, pos.Longitude),
                        IsDraggable = true,
                        Icon        = BitmapDescriptorFactory.DefaultMarker(Color.Gray)
                    };
                    // Pins.Add(localAtualPin);
                    MoveToRegionReq.MoveToRegion(MapSpan.FromCenterAndRadius(localAtualPin.Position, Distance.FromKilometers(0.3)));
                }
                else
                {
                    Pin inicioPin = new Pin()
                    {
                        Type        = PinType.Place,
                        Label       = "Início",
                        Position    = lista[0],
                        IsDraggable = true,
                        Icon        = BitmapDescriptorFactory.DefaultMarker(Color.Green)
                    };
                    Pins.Add(inicioPin);

                    Pin finalPin = new Pin()
                    {
                        Type        = PinType.Place,
                        Label       = "Final",
                        Position    = lista[lista.Count - 1],
                        IsDraggable = true,
                        Icon        = BitmapDescriptorFactory.FromBundle("chegada.png")
                    };
                    Pins.Add(finalPin);
                    DesenharRota(lista);
                    //var polyline = new Polyline();
                    //foreach (Position posi in lista)
                    //{
                    //    polyline.Positions.Add(posi);
                    //}
                    ////polyline.Positions.Add(new Position(40.77d, -73.93d));
                    ////polyline.Positions.Add(new Position(40.81d, -73.91d));
                    ////polyline.Positions.Add(new Position(40.83d, -73.87d));
                    //polyline.IsClickable = true;
                    //polyline.StrokeColor = Color.Blue;
                    //polyline.StrokeWidth = 2f;
                    //Polylines.Add(polyline);
                    MoveToRegionReq.MoveToRegion(MapSpan.FromCenterAndRadius(lista[0], Distance.FromKilometers(0.6)));
                }
            }
            else
            {
                if (CrossSettings.Current.Contains("ChamadaEmCorrida"))
                {
                    Pin localAtualPin = new Pin()
                    {
                        Type        = PinType.Place,
                        Label       = "Atual",
                        Position    = new Position(pos.Latitude, pos.Longitude),
                        IsDraggable = true,
                        Icon        = BitmapDescriptorFactory.DefaultMarker(Color.Blue)
                    };

                    Pin finalPin = new Pin()
                    {
                        Type        = PinType.Place,
                        Label       = "Final",
                        Position    = lista[lista.Count - 1],
                        IsDraggable = true,
                        Icon        = BitmapDescriptorFactory.FromBundle("chegada.png")
                    };
                    Pins.Add(finalPin);

                    DesenharRota(lista);
                    //var polyline = new Polyline();
                    //foreach (Position posi in lista)
                    //{
                    //    polyline.Positions.Add(posi);
                    //}
                    ////polyline.Positions.Add(new Position(40.77d, -73.93d));
                    ////polyline.Positions.Add(new Position(40.81d, -73.91d));
                    ////polyline.Positions.Add(new Position(40.83d, -73.87d));
                    //polyline.IsClickable = true;
                    //polyline.StrokeColor = Color.Green;
                    //polyline.StrokeWidth = 2f;
                    //Polylines.Add(polyline);

                    // Pins.Add(localAtualPin);
                    MoveToRegionReq.MoveToRegion(MapSpan.FromCenterAndRadius(localAtualPin.Position, Distance.FromKilometers(0.6)));
                }
                else
                {
                    Pin localAtualPin = new Pin()
                    {
                        Type        = PinType.Place,
                        Label       = "Atual",
                        Position    = new Position(pos.Latitude, pos.Longitude),
                        IsDraggable = true,
                        // Icon = BitmapDescriptorFactory.FromBundle("capacete.png")
                        Icon = BitmapDescriptorFactory.DefaultMarker(Color.Blue)
                    };
                    Pins.Add(localAtualPin);
                    //  MoveToRegionReq.MoveToRegion(MapSpan.FromCenterAndRadius(localAtualPin.Position, Distance.FromKilometers(0.3)));

                    Pin inicioPin = new Pin()
                    {
                        Type        = PinType.Place,
                        Label       = "Início",
                        Position    = new Position(Double.Parse(Chamada.latitudeOrigem), Double.Parse(Chamada.longitudeOrigem)),
                        IsDraggable = true,
                        Icon        = BitmapDescriptorFactory.DefaultMarker(Color.Green)
                    };
                    Pins.Add(inicioPin);

                    DesenharRota(DecodePolylinePoints(Chamada.polylinesParaOrigem));
                    MoveToRegionReq.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(pos.Latitude, pos.Longitude), Distance.FromKilometers(1.0)));
                }
            }
        }