async void Update(Xamarin.Forms.GoogleMaps.Position position)
        {
            if (map.Pins.Count == 1)
            {
                return;
            }

            var cPin = map.Pins.FirstOrDefault();

            if (cPin != null)
            {
                cPin.Position = new Position(position.Latitude, position.Longitude);
                cPin.Icon     = BitmapDescriptorFactory.FromView(new Image()
                {
                    Source = "ic_taxi.png", WidthRequest = 25, HeightRequest = 25
                });

                await map.MoveCamera(CameraUpdateFactory.NewPosition(new Position(position.Latitude, position.Longitude)));

                var previousPosition = map.Polylines.FirstOrDefault().Positions.FirstOrDefault();
                map.Polylines?.FirstOrDefault()?.Positions?.Remove(previousPosition);
            }
            else
            {
                //END TRIP
                map.Polylines?.FirstOrDefault()?.Positions?.Clear();
            }
        }
        async void UpdateRoute(Xamarin.Forms.GoogleMaps.Position position)
        {
            if (map.Pins.Count == 1 && map.Polylines != null && map.Polylines?.Count > 1)
            {
                return;
            }

            var cPin = map.Pins.FirstOrDefault();

            if (cPin != null)
            {
                cPin.Position = new Position(position.Latitude, position.Longitude);
                cPin.Icon     = (Device.RuntimePlatform == Device.iOS) ? BitmapDescriptorFactory.FromView(new Image()
                {
                    Source        = "car.png",
                    WidthRequest  = 25,
                    HeightRequest = 25
                }) : BitmapDescriptorFactory.DefaultMarker(Color.Purple);

                await map.MoveCamera(CameraUpdateFactory.NewPosition(new Position(position.Latitude, position.Longitude)));

                var previousPosition = map?.Polylines?.FirstOrDefault()?.Positions?.FirstOrDefault();
                map.Polylines?.FirstOrDefault()?.Positions?.Remove(previousPosition.Value);
            }
            else
            {
                //END TRIP
                map.Polylines?.FirstOrDefault()?.Positions?.Clear();
            }
        }
示例#3
0
        async void Update(Xamarin.Forms.GoogleMaps.Position position)
        {
            if (Pins.Count == 1 && Polylines != null && Polylines?.Count > 1)
            {
                return;
            }

            var cPin = Pins.FirstOrDefault();

            if (cPin != null)
            {
                cPin.Position = new Position(position.Latitude, position.Longitude);
                cPin.Icon     = (Device.RuntimePlatform == Device.Android) ? BitmapDescriptorFactory.FromBundle("ic_taxi.png") : BitmapDescriptorFactory.FromView(new Image()
                {
                    Source = "ic_taxi.png", WidthRequest = 25, HeightRequest = 25
                });

                await MoveCamera(CameraUpdateFactory.NewPosition(new Position(position.Latitude, position.Longitude)));

                var previousPosition = Polylines?.FirstOrDefault()?.Positions?.FirstOrDefault();
                Polylines?.FirstOrDefault()?.Positions?.Remove(previousPosition.Value);
            }
            else
            {
                //END TRIP
                Polylines?.FirstOrDefault()?.Positions?.Clear();
            }
        }
 private async void ListView_ItemTapped(object sender, ItemTappedEventArgs e)
 {
     ViewModel.ShowOrHideListModels(e.Item as PinViewModel, (map.Pins as ObservableCollection <Pin>));
     //map.SelectedPin = ViewModel.FocusedPin;
     if (ViewModel.FocusedPin != null)
     {
         await map.AnimateCamera(CameraUpdateFactory.NewPosition(ViewModel.FocusedPin.Position));
     }
 }
示例#5
0
        //this needs to be asynchronous because awaititng in the main thread causes a deadlock
        //sets the camera on user position if available
        async Task InitAsync()
        {
            locator = CrossGeolocator.Current;

            try
            {
                var pos = await locator.GetPositionAsync();

                await map.MoveCamera(CameraUpdateFactory.NewPosition(new Xamarin.Forms.GoogleMaps.Position(pos.Latitude, pos.Longitude)));
            }
            catch { }
        }
示例#6
0
        public async void MyPositionClicked(object sender, EventArgs e)
        {
            try
            {
                var pos = VM.CurrentLocation;

                var update = CameraUpdateFactory.NewPosition(new Position(pos.Latitude, pos.Longitude));

                await TheMap.AnimateCamera(update, TimeSpan.FromMilliseconds(200));
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
            }
        }
示例#7
0
        public override object ConvertFromInvariantString(string value)
        {
            var err    = $@"{value} is invalid format. Expects are ""lat, lon"", ""lat, lon, zoom"", ""lat, lon, zoom, rotation"" and ""lat, lon, zoom, rotation, tilt"" ";
            var values = value.Split(',');

            if (values.Length < 2)
            {
                throw new ArgumentException(err);
            }

            var nums = new List <double>();

            foreach (var v in values)
            {
                double ret;
                if (!double.TryParse(v, out ret))
                {
                    throw new ArgumentException(err);
                }
                nums.Add(ret);
            }

            if (nums.Count == 2)
            {
                return(CameraUpdateFactory.NewPosition(new Position(nums[0], nums[1])));
            }

            if (nums.Count == 3)
            {
                return(CameraUpdateFactory.NewPositionZoom(new Position(nums[0], nums[1]), nums[2]));
            }

            if (nums.Count == 4)
            {
                return(CameraUpdateFactory.NewCameraPosition(new CameraPosition(
                                                                 new Position(nums[0], nums[1]),
                                                                 nums[2],
                                                                 nums[3])));
            }

            return(CameraUpdateFactory.NewCameraPosition(new CameraPosition(
                                                             new Position(nums[0], nums[1]),
                                                             nums[2],
                                                             nums[3],
                                                             nums[4])));
        }
        async void Update(Xamarin.Forms.GoogleMaps.Position position)
        {
            if (mapn.Pins.Count == 1 && mapn.Polylines != null && mapn.Polylines?.Count > 1)
            {
                return;
            }
            var cPin = mapn.Pins.FirstOrDefault();

            if (cPin != null)
            {
                cPin.Position = new Position(position.Latitude, position.Longitude);
                cPin.Icon     = BitmapDescriptorFactory.FromView(new Image()
                {
                    Source = "ic_taxi.png", WidthRequest = 25, HeightRequest = 25
                });

                await mapn.MoveCamera(CameraUpdateFactory.NewPosition(new Position(position.Latitude, position.Longitude)));
            }
        }
示例#9
0
        public CameraPage()
        {
            InitializeComponent();

            var pinMelbourne = new Pin()
            {
                Label = "Melbourne", Position = new Position(-37.971237, 144.492697)
            };
            var pinNewyork = new Pin()
            {
                Label = "New york", Position = new Position(40.705311, -74.2581874)
            };
            var pinLisboa = new Pin()
            {
                Label = "Lisboa", Position = new Position(38.7436057, -13.6426275)
            };
            var pinParis = new Pin()
            {
                Label = "Paris", Position = new Position(48.8588377, 2.2775173)
            };
            var pinTokyo = new Pin()
            {
                Label = "Tokyo", Position = new Position(35.7104, 139.8093)
            };

            map.Pins.Add(pinMelbourne);
            map.Pins.Add(pinNewyork);
            map.Pins.Add(pinLisboa);
            map.Pins.Add(pinParis);
            map.Pins.Add(pinTokyo);

            // CameraChanged is obsolete, please use CameraIdled
            map.CameraChanged += (sender, e) =>
            {
                var p    = e.Position;
                var text = $"CameraChanged:Lat={p.Target.Latitude:0.00}, Long={p.Target.Longitude:0.00}, Zoom={p.Zoom:0.00}, Bearing={p.Bearing:0.00}, Tilt={p.Tilt:0.00}";
                labelStatus.Text = text;
                Debug.WriteLine(text);
            };

            map.CameraMoveStarted += (sender, e) =>
            {
                var text = $"CameraMoveStarted:IsGesture={e.IsGesture}";
                labelStatus.Text = text;
                Debug.WriteLine(text);
            };

            map.CameraMoving += (sender, e) =>
            {
                var p    = e.Position;
                var text = $"CameraMoving:Lat={p.Target.Latitude:0.00}, Long={p.Target.Longitude:0.00}, Zoom={p.Zoom:0.00}, Bearing={p.Bearing:0.00}, Tilt={p.Tilt:0.00}";
                labelStatus.Text = text;
                Debug.WriteLine(text);
            };

            map.CameraIdled += (sender, e) =>
            {
                var p    = e.Position;
                var text = $"CameraIdled:Lat={p.Target.Latitude:0.00}, Long={p.Target.Longitude:0.00}, Zoom={p.Zoom:0.00}, Bearing={p.Bearing:0.00}, Tilt={p.Tilt:0.00}";
                labelStatus.Text = text;
                Debug.WriteLine(text);

                UpdateCornerPins();
            };

            // MoveToCamera with Position
            buttonMoveToPosition.Clicked += async(sender, e) =>
            {
                await map.MoveCamera(CameraUpdateFactory.NewPosition(
                                         pinMelbourne.Position)); // Melbourne
            };

            // MoveToCamera with Position and Zoom
            buttonMoveToPositionZoom.Clicked += async(sender, e) =>
            {
                await map.MoveCamera(CameraUpdateFactory.NewPositionZoom(
                                         pinNewyork.Position, 16d)); // New york
            };

            // MoveToCamera with Bounds
            buttonMoveToBounds.Clicked += async(sender, e) =>
            {
                await map.MoveCamera(CameraUpdateFactory.NewBounds(
                                         new Bounds(pinLisboa.Position, // Lisboa
                                                    pinParis.Position), // Paris
                                         50));                          // 50px
            };

            // MoveToCamera with CameraPosition
            buttonMoveToCameraPosition.Clicked += async(sender, e) =>
            {
                await map.MoveCamera(CameraUpdateFactory.NewCameraPosition(
                                         new CameraPosition(
                                             pinTokyo.Position, // Tokyo
                                             17d,               // zoom
                                             45d,               // bearing(rotation)
                                             60d                // tilt
                                             )));
            };

            // AnimateToCamera with Position
            buttonAnimateToPosition.Clicked += async(sender, e) =>
            {
                var animState = await map.AnimateCamera(CameraUpdateFactory.NewPosition(
                                                            pinMelbourne.Position)); // Melbourne

                Debug.WriteLine($"Animate with Position result = {animState}");
            };

            // AnimateToCamera with Position and Zoom
            buttonAnimateToPositionZoom.Clicked += async(sender, e) =>
            {
                var animState = await map.AnimateCamera(CameraUpdateFactory.NewPositionZoom(
                                                            pinNewyork.Position, 16d), TimeSpan.FromSeconds(1)); // New york

                Debug.WriteLine($"Animate with Position and Zoom result = {animState}");
            };

            // AnimateToCamera with Bounds
            buttonAnimateToBounds.Clicked += async(sender, e) =>
            {
                var animState = await map.AnimateCamera(CameraUpdateFactory.NewBounds(
                                                            new Bounds(pinLisboa.Position, // Lisboa
                                                                       pinParis.Position), // Paris
                                                            50), TimeSpan.FromSeconds(3)); // 50px

                Debug.WriteLine($"Animate with Bounds result = {animState}");
            };

            // AnimateToCamera with CameraPosition
            buttonAnimateToCameraPosition.Clicked += async(sender, e) =>
            {
                var animState = await map.AnimateCamera(CameraUpdateFactory.NewCameraPosition(
                                                            new CameraPosition(
                                                                pinTokyo.Position, // Tokyo
                                                                17d,               // zoom
                                                                45d,               // bearing(rotation)
                                                                60d)),             // tilt
                                                        TimeSpan.FromSeconds(5));

                Debug.WriteLine($"Animate with CameraPosition result = {animState}");
            };

            // Padding for Map
            entryPadding.TextChanged += (sender, e) =>
            {
                try
                {
                    var converter = new ThicknessTypeConverter();
                    var padding   = (Thickness)converter.ConvertFromInvariantString(entryPadding.Text);
                    map.Padding = padding;
                }
                catch (Exception)
                {
                }
            };
            map.Padding = new Thickness(0, 0, 0, 0);
        }
        public CameraPage()
        {
            InitializeComponent();

            var pinMelbourne = new Pin()
            {
                Label = "Melbourne", Position = new Position(-37.971237, 144.492697)
            };
            var pinNewyork = new Pin()
            {
                Label = "New york", Position = new Position(40.705311, -74.2581874)
            };
            var pinLisboa = new Pin()
            {
                Label = "Lisboa", Position = new Position(38.7436057, -13.6426275)
            };
            var pinParis = new Pin()
            {
                Label = "Paris", Position = new Position(48.8588377, 2.2775173)
            };
            var pinTokyo = new Pin()
            {
                Label = "Tokyo", Position = new Position(35.7104, 139.8093)
            };

            map.Pins.Add(pinMelbourne);
            map.Pins.Add(pinNewyork);
            map.Pins.Add(pinLisboa);
            map.Pins.Add(pinParis);
            map.Pins.Add(pinTokyo);

            map.CameraChanged += (sender, e) =>
            {
                var p = e.Position;
                labelStatus.Text = $"Lat={p.Target.Latitude:0.00}, Long={p.Target.Longitude:0.00}, Zoom={p.Zoom:0.00}, Bearing={p.Bearing:0.00}, Tilt={p.Tilt:0.00}";
            };

            // MoveToCamera with Position
            buttonMoveToPosition.Clicked += async(sender, e) =>
            {
                await map.MoveCamera(CameraUpdateFactory.NewPosition(
                                         pinMelbourne.Position)); // Melbourne
            };

            // MoveToCamera with Position and Zoom
            buttonMoveToPositionZoom.Clicked += async(sender, e) =>
            {
                await map.MoveCamera(CameraUpdateFactory.NewPositionZoom(
                                         pinNewyork.Position, 16d)); // New york
            };

            // MoveToCamera with Bounds
            buttonMoveToBounds.Clicked += async(sender, e) =>
            {
                await map.MoveCamera(CameraUpdateFactory.NewBounds(
                                         new Bounds(pinLisboa.Position, // Lisboa
                                                    pinParis.Position), // Paris
                                         50));                          // 50px
            };

            // MoveToCamera with CameraPosition
            buttonMoveToCameraPosition.Clicked += async(sender, e) =>
            {
                await map.MoveCamera(CameraUpdateFactory.NewCameraPosition(
                                         new CameraPosition(
                                             pinTokyo.Position, // Tokyo
                                             45d,               // bearing(rotation)
                                             60d,               // tilt
                                             17d)));
            };

            // AnimateToCamera with Position
            buttonAnimateToPosition.Clicked += async(sender, e) =>
            {
                var animState = await map.AnimateCamera(CameraUpdateFactory.NewPosition(
                                                            pinMelbourne.Position)); // Melbourne

                Debug.WriteLine($"Animate with Position result = {animState}");
            };

            // AnimateToCamera with Position and Zoom
            buttonAnimateToPositionZoom.Clicked += async(sender, e) =>
            {
                var animState = await map.AnimateCamera(CameraUpdateFactory.NewPositionZoom(
                                                            pinNewyork.Position, 16d), TimeSpan.FromSeconds(1)); // New york

                Debug.WriteLine($"Animate with Position and Zoom result = {animState}");
            };

            // AnimateToCamera with Bounds
            buttonAnimateToBounds.Clicked += async(sender, e) =>
            {
                var animState = await map.AnimateCamera(CameraUpdateFactory.NewBounds(
                                                            new Bounds(pinLisboa.Position, // Lisboa
                                                                       pinParis.Position), // Paris
                                                            50), TimeSpan.FromSeconds(3)); // 50px

                Debug.WriteLine($"Animate with Bounds result = {animState}");
            };

            // AnimateToCamera with CameraPosition
            buttonAnimateToCameraPosition.Clicked += async(sender, e) =>
            {
                var animState = await map.AnimateCamera(CameraUpdateFactory.NewCameraPosition(
                                                            new CameraPosition(
                                                                pinTokyo.Position, // Tokyo
                                                                45d,               // bearing(rotation)
                                                                60d,               // tilt
                                                                17d)),
                                                        TimeSpan.FromSeconds(5));

                Debug.WriteLine($"Animate with CameraPosition result = {animState}");
            };
        }
示例#11
0
        private async void TrackMeAsync()
        {
            var current = await CrossGeolocator.Current.GetPositionAsync();

            current.Accuracy = 30;
            float bearing = float.Parse(current.Heading.ToString());


            var pinsUsuario = new Pin
            {
                Label        = "Eu estou aqui",
                IsDraggable  = true,
                Icon         = BitmapDescriptorFactory.FromBundle("pinManopla.png"),
                Transparency = 3 / 10f,
                Flat         = true
            };



            Device.BeginInvokeOnMainThread(() =>
            {
                pinsUsuario.Position = new Position(current.Latitude, current.Longitude);
                pinsUsuario.Rotation = bearing;


                lstRotaFuga = new List <RotaFuga>();


                lstRotaFuga = new RestRotaFuga().RestGet();

                foreach (var item in lstRotaFuga)
                {
                    var pins = new Pin
                    {
                        Label = item.Endereco,


                        Icon         = BitmapDescriptorFactory.FromBundle("pinPontoEncontro.png"),
                        Transparency = 3 / 10f,
                        Flat         = true
                    };
                    pins.Position = new Position(double.Parse(item.Latitude), double.Parse(item.Longitude));
                    pins.Rotation = bearing;
                    //pins.Clicked += new EventHandler(ChamarCuidador);
                    map.Pins.Add(pins);
                }



                //foreach (var item in lstEnfermeiras)
                //{
                //    var pins = new Pin
                //    {
                //        Label = item.Nome,


                //        Icon = BitmapDescriptorFactory.FromBundle("pinEnfermagem.png"),
                //        Transparency = 3 / 10f,
                //        Flat = true
                //    };
                //    pins.Position = new Position(double.Parse(item.Latitude.Replace(".", ",")), double.Parse(item.Longitude.Replace(".", ",")));
                //    pins.Rotation = bearing;
                //    pins.Clicked += new EventHandler(ChamarEnfermagem);
                //    map.Pins.Add(pins);
                //}



                // add the polygon to the map's MapElements collection
                map.UiSettings.ZoomGesturesEnabled      = true;
                map.UiSettings.ZoomControlsEnabled      = true;
                map.UiSettings.TiltGesturesEnabled      = true;
                map.UiSettings.MyLocationButtonEnabled  = true;
                map.UiSettings.MapToolbarEnabled        = true;
                map.UiSettings.IndoorLevelPickerEnabled = true;
                map.Pins.Add(pinsUsuario);
                map.IsTrafficEnabled  = true;
                map.IsShowingUser     = true;
                map.IsIndoorEnabled   = true;
                map.MyLocationEnabled = true;

                map.MoveCamera(CameraUpdateFactory.NewPosition(new Position(current.Latitude, current.Longitude)));
            });
        }
示例#12
0
        private async void TrackMeAsync()
        {
            var current = await CrossGeolocator.Current.GetPositionAsync();

            current.Accuracy = 30;
            float bearing = float.Parse(current.Heading.ToString());


            var pinsUsuario = new Pin
            {
                Label        = "Eu estou aqui",
                IsDraggable  = true,
                Icon         = BitmapDescriptorFactory.FromBundle("pinManopla.png"),
                Transparency = 3 / 10f,
                Flat         = true
            };



            Device.BeginInvokeOnMainThread(() =>
            {
                pinsUsuario.Position = new Position(current.Latitude, current.Longitude);
                pinsUsuario.Rotation = bearing;
                //if (map.Pins.Count == 0)
                //{


                //    //lstUsuarioVO = new List<UsuarioVO>();
                //    //lstCuidador = new List<UsuarioVO>();
                //    //lstEnfermeiras = new List<UsuarioVO>();


                //    //lstUsuarioVO = new RestUsuario().RestGet();
                //    //lstCuidador = lstUsuarioVO.Where(i => i.Grupo_usuario_id == 51470639).ToList();
                //    //lstEnfermeiras = lstUsuarioVO.Where(i => i.Grupo_usuario_id == 16335373).ToList();

                //    //foreach (var item in lstCuidador)
                //    //{
                //    //    var pins = new Pin
                //    //    {
                //    //        Label = item.Nome,


                //    //        Icon = BitmapDescriptorFactory.FromBundle("pinRoxo.png"),
                //    //        Transparency = 3 / 10f,
                //    //        Flat = true
                //    //    };
                //    //    pins.Position = new Position(double.Parse(item.Latitude.Replace(".", ",")), double.Parse(item.Longitude.Replace(".", ",")));
                //    //    pins.Rotation = bearing;
                //    //    pins.Clicked += new EventHandler(ChamarCuidador);
                //    //    map.Pins.Add(pins);
                //    //}



                //    //foreach (var item in lstEnfermeiras)
                //    //{
                //    //    var pins = new Pin
                //    //    {
                //    //        Label = item.Nome,


                //    //        Icon = BitmapDescriptorFactory.FromBundle("pinEnfermagem.png"),
                //    //        Transparency = 3 / 10f,
                //    //        Flat = true
                //    //    };
                //    //    pins.Position = new Position(double.Parse(item.Latitude.Replace(".", ",")), double.Parse(item.Longitude.Replace(".", ",")));
                //    //    pins.Rotation = bearing;
                //    //    pins.Clicked += new EventHandler(ChamarEnfermagem);
                //    //    map.Pins.Add(pins);
                //    //}


                //    map.Pins.Add(pinsUsuario);
                //}

                mapaRotaFuga.Pins.Add(pinsUsuario);
                mapaRotaFuga.IsTrafficEnabled  = true;
                mapaRotaFuga.IsShowingUser     = true;
                mapaRotaFuga.IsIndoorEnabled   = true;
                mapaRotaFuga.MyLocationEnabled = true;

                mapaRotaFuga.MoveCamera(CameraUpdateFactory.NewPosition(new Position(current.Latitude, current.Longitude)));
            });
        }