Beispiel #1
0
        /// <summary>
        /// Focuses the on whole game.
        /// </summary>
        void FocusOnGame()
        {
            double latNorth, latSouth;
            double longWest, longEast;

            // Get correct latitude
            if (ctrl.Engine.Bounds.Right > ctrl.Engine.Bounds.Left)
            {
                latNorth = ctrl.Engine.Bounds.Right;
                latSouth = ctrl.Engine.Bounds.Left;
            }
            else
            {
                latNorth = ctrl.Engine.Bounds.Left;
                latSouth = ctrl.Engine.Bounds.Right;
            }

            // Get correct latitude
            if (ctrl.Engine.Bounds.Top > ctrl.Engine.Bounds.Bottom)
            {
                longWest = ctrl.Engine.Bounds.Bottom;
                longEast = ctrl.Engine.Bounds.Top;
            }
            else
            {
                longWest = ctrl.Engine.Bounds.Top;
                longEast = ctrl.Engine.Bounds.Bottom;
            }

            CameraUpdate cu = CameraUpdateFactory.NewLatLngBounds(new LatLngBounds(new LatLng(latSouth, longWest), new LatLng(latNorth, longEast)), 10);

            _map.MoveCamera(cu);
        }
Beispiel #2
0
        public void OnMapReady(GoogleMap googleMap)
        {
            List <List <Localization> > Localizations = new List <List <Localization> >();

            LatLngBounds.Builder builder = new LatLngBounds.Builder();
            if (Training.SerializedLocalizations != null && Training.SerializedLocalizations.Length > 0)
            {
                IFormatter formatter = new BinaryFormatter();
                using (MemoryStream stream = new MemoryStream(Training.SerializedLocalizations))
                {
                    Localizations = formatter.Deserialize(stream) as List <List <Localization> >;
                }
            }
            foreach (var path in Localizations)
            {
                PolylineOptions options = new PolylineOptions()
                                          .InvokeColor((new Color(105, 121, 176, 200).ToArgb()))
                                          .InvokeWidth(20);
                foreach (var point in path)
                {
                    options.Add(new LatLng(point.Latitude, point.Longitude));
                    builder.Include(new LatLng(point.Latitude, point.Longitude));
                }
                googleMap.AddPolyline(options);
            }
            LatLngBounds bounds = builder.Build();
            // begin new code:
            int width   = Resources.DisplayMetrics.WidthPixels;
            int height  = Resources.DisplayMetrics.HeightPixels;
            int padding = (int)(width * 0.05);

            CameraUpdate cameraUpdate = CameraUpdateFactory.NewLatLngBounds(bounds, width, height, padding);

            googleMap.AnimateCamera(cameraUpdate);
        }
Beispiel #3
0
        /// <summary>
        /// Render the route planning result
        /// </summary>
        /// <param name="paths">paths</param>
        /// <param name="latLngBounds">latLngBounds</param>
        private void renderRoute(List <List <LatLng> > paths, LatLngBounds latLngBounds)
        {
            if (paths == null || paths.Count <= 0 || paths.ElementAt(0).Count <= 0)
            {
                return;
            }

            for (int i = 0; i < paths.Count; i++)
            {
                List <LatLng>   path    = paths.ElementAt(i);
                PolylineOptions options = new PolylineOptions().InvokeColor(Color.Blue).InvokeWidth(5);
                foreach (LatLng latLng in path)
                {
                    options.Add(latLng);
                }

                Polyline polyline = hMap.AddPolyline(options);
                mPolylines.Add(polyline);
            }

            AddOriginMarker(paths.ElementAt(0).ElementAt(0));
            AddDestinationMarker(paths.ElementAt(0).ElementAt(paths.ElementAt(0).Count - 1));

            if (null != latLngBounds)
            {
                CameraUpdate cameraUpdate = CameraUpdateFactory.NewLatLngBounds(latLngBounds, 5);
                hMap.MoveCamera(cameraUpdate);
            }
            else
            {
                hMap.MoveCamera(CameraUpdateFactory.NewLatLngZoom(paths.ElementAt(0).ElementAt(0), 13));
            }
        }
        public void MoveToRegion(MapRegion region, bool animated)
        {
            if (_googleMap == null)
            {
                return;
            }

            var cameraUpdate = CameraUpdateFactory.NewLatLngBounds(region.ToBounds(), 0);

            if (Map.ZoomLevel != -1)
            {
                cameraUpdate = CameraUpdateFactory.NewLatLngZoom(new LatLng(region.Center.Latitude, region.Center.Longitude), Map.ZoomLevel);
            }
            else if (_requestedShowUserLocation)
            {
                cameraUpdate = CameraUpdateFactory.NewLatLngZoom(new LatLng(region.Center.Latitude, region.Center.Longitude), 16);
            }

            try
            {
                if (animated)
                {
                    _googleMap.AnimateCamera(cameraUpdate);
                }
                else
                {
                    _googleMap.MoveCamera(cameraUpdate);
                }
            }
            catch (IllegalStateException e)
            {
                Console.WriteLine("MoveToRegion exception: " + e);
            }
        }
        public void OnMapReady(MapboxMap map)
        {
            var uiSettings = map.UiSettings;

            uiSettings.SetAllGesturesEnabled(true);

            var marker = new MarkerOptions();

            marker.SetTitle("Los Angeles");
            marker.SetSnippet("City Hall");
            marker.SetPosition(LOS_ANGELES);

            map.AddMarker(marker);

            marker.SetTitle("New York");
            marker.SetSnippet("City Hall");
            marker.SetPosition(NEW_YORK);

            map.AddMarker(marker);

            var bounds = new LatLngBounds.Builder()
                         .Include(NEW_YORK)
                         .Include(LOS_ANGELES)
                         .Build();

            map.MoveCamera(CameraUpdateFactory.NewLatLngBounds(bounds, 8));
        }
        public bool OnClusterClick(ICluster p0)
        {
            // zoom to expand the cluster
            LatLngBounds.Builder builder = new LatLngBounds.Builder();
            foreach (var item in p0.Items)
            {
                var clusterMarker = item as ClusterMarker;
                if (clusterMarker.Position != null)
                {
                    builder.Include(clusterMarker.Position);
                }
            }
            LatLngBounds bounds = builder.Build();

            try
            {
                googleMap.AnimateCamera(CameraUpdateFactory.NewLatLngBounds(bounds, 100));
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }

            return(true);
        }
Beispiel #7
0
        private void moveCameraToKml(KmlLayer kmlLayer)
        {
            if (mIsRestore)
            {
                return;
            }
            try
            {
                //Retrieve the first container in the KML layer
                KmlContainer container = (KmlContainer)kmlLayer.Containers.Iterator().Next();
                //Retrieve a nested container within the first container
                container = (KmlContainer)container.Containers.Iterator().Next();
                //Retrieve the first placemark in the nested container
                KmlPlacemark placemark = (KmlPlacemark)container.Placemarks.Iterator().Next();
                //Retrieve a polygon object in a placemark
                KmlPolygon polygon = (KmlPolygon)placemark.Geometry;
                //Create LatLngBounds of the outer coordinates of the polygon
                LatLngBounds.Builder builder = new LatLngBounds.Builder();
                foreach (LatLng latLng in polygon.OuterBoundaryCoordinates)
                {
                    builder.Include(latLng);
                }

                int width  = Resources.DisplayMetrics.WidthPixels;
                int height = Resources.DisplayMetrics.HeightPixels;
                getMap().MoveCamera(CameraUpdateFactory.NewLatLngBounds(builder.Build(), width, height, 1));
            }
            catch (Java.Lang.Exception e)
            {
                // may fail depending on the KML being shown
                e.PrintStackTrace();
            }
        }
        public void DarZoom(LatLngBounds bounds, int margem)
        {
            CameraUpdate camera = CameraUpdateFactory.NewLatLngBounds(bounds, margem);


            Mapa.MoveCamera(camera);
        }
        private void DrawTracksButton_Click(object sender, EventArgs e)
        {
            var points = journeyPointRespository.GetTrackPointsForJourney(SelectedJourneyId);

            LatLngBounds.Builder builder = new LatLngBounds.Builder();
            PolylineOptions      line    = new PolylineOptions().InvokeColor(Color.Purple);


            if (points.Count() > 0)
            {
                MarkerOptions moStart = new MarkerOptions();
                moStart.SetPosition(new LatLng(points.ElementAt(0).Lat, points.ElementAt(0).Lon));
                moStart.SetIcon((BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueGreen)));

                foreach (var v in points)
                {
                    LatLng l = new LatLng(v.Lat, v.Lon);
                    builder.Include(l);
                    line.Add(l);
                }

                MarkerOptions moEnd = new MarkerOptions();
                moEnd.SetPosition(new LatLng(points.ElementAt(points.Count() - 1).Lat, points.ElementAt(points.Count() - 1).Lon));
                moEnd.SetIcon((BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueRed)));

                _map.AddPolyline(line);
                _map.AddMarker(moStart);
                _map.AddMarker(moEnd);
                _map.MoveCamera(CameraUpdateFactory.NewLatLngBounds(builder.Build(), 80));
            }
        }
Beispiel #10
0
        void MoveToRegion(MapSpan span, bool animate)
        {
            GoogleMap map = NativeMap;

            if (map == null)
            {
                return;
            }

            span = span.ClampLatitude(85, -85);
            var ne = new LatLng(span.Center.Latitude + span.LatitudeDegrees / 2,
                                span.Center.Longitude + span.LongitudeDegrees / 2);
            var sw = new LatLng(span.Center.Latitude - span.LatitudeDegrees / 2,
                                span.Center.Longitude - span.LongitudeDegrees / 2);
            CameraUpdate update = CameraUpdateFactory.NewLatLngBounds(new LatLngBounds(sw, ne), 0);

            try
            {
                if (animate)
                {
                    map.AnimateCamera(update);
                }
                else
                {
                    map.MoveCamera(update);
                }
            }
            catch (IllegalStateException exc)
            {
                System.Diagnostics.Debug.WriteLine("MoveToRegion exception: " + exc);
                Log.Warning("Xamarin.Forms MapRenderer", $"MoveToRegion exception: {exc}");
            }
        }
Beispiel #11
0
        void ZoomToMyLocationAndAlarms()
        {
            var location = MyCurrentLocation;

            if (_mapData.Count > 0)
            {
                var boundsBuilder = new LatLngBounds.Builder();

                foreach (var alarm in _mapData)
                {
                    boundsBuilder.Include(new LatLng(alarm.Latitude, alarm.Longitude));
                }

                if (location != null)
                {
                    boundsBuilder.Include(new LatLng(location.Latitude, location.Longitude));
                }

                try {
                    _map.AnimateCamera(CameraUpdateFactory.NewLatLngBounds(boundsBuilder.Build(), 200));
                    Log.Debug(TAG, "map zoomed with NewLatLngBounds");
                } catch {
                    Log.Debug(TAG, "exception while zooming with NewLatLngBounds");
                }
            }
            else
            {
                AnimateTo(location);
            }
        }
Beispiel #12
0
        private void ShowRouteOverview()
        {
            NativeMap.Clear();

            PolylineOptions selectedRoutePolyline = new PolylineOptions();

            selectedRoutePolyline.InvokeColor(Resource.Color.colorPrimaryDark);
            selectedRoutePolyline.InvokeWidth(20f);

            LatLng[] allRoutePoints = _xamap.SelectedRoute.Legs
                                      .SelectMany(leg => leg.Points)
                                      .Select(point => new LatLng(point.Latitude, point.Longitude))
                                      .ToArray();

            selectedRoutePolyline.Add(allRoutePoints);
            NativeMap.AddPolyline(selectedRoutePolyline);

            LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder();
            LatLngBounds         routeBounds   = allRoutePoints
                                                 .Aggregate(boundsBuilder, (builder, latLng) => builder.Include(latLng))
                                                 .Build();

            CameraUpdate routeOverviewMapUpdate = CameraUpdateFactory.NewLatLngBounds(routeBounds, 50);

            NativeMap.AnimateCamera(routeOverviewMapUpdate);
        }
Beispiel #13
0
        private void ShowTheWay()
        {
            PolylineOptions polylineOptions = new PolylineOptions();
            LatLngBounds    bounds;

            LatLng[] points = location.getPath(sourceMarkerOptions.Position, destinationMarkerOptions.Position, out bounds);
            polylineOptions.Add(points);
            googleMap.AddPolyline(polylineOptions);

            var filteredSites = location.allSites.Where(x => bounds.Contains(x.Item1));


            googleMap.AnimateCamera(CameraUpdateFactory.NewLatLngBounds(bounds, 60), 2000, null);


            inputManager.HideSoftInputFromWindow(this.CurrentFocus.WindowToken, HideSoftInputFlags.None);

            foreach (var site in filteredSites)
            {
                var markerOp = new MarkerOptions();
                markerOp.SetPosition(site.Item1);
                markerOp.SetTitle(site.Item2);
                googleMap.AddMarker(markerOp);
            }
        }
Beispiel #14
0
        public void OnMapReady(GoogleMap googleMap)
        {
            var Map = googleMap;
            IList <MarkerOptions> markers = new List <MarkerOptions>();
            var trips = AppStore.Instance.User.Trips;

            Map.Clear();
            foreach (var trip in trips)
            {
                var places = trip.Places;
                foreach (var place in places)
                {
                    var marker = new MarkerOptions();
                    marker.SetPosition(new LatLng(place.Latitude, place.Longitude));
                    marker.SetTitle(place.Name);
                    Map.AddMarker(marker);
                    markers.Add(marker);
                    //Map.MoveCamera(CameraUpdateFactory.NewLatLngZoom(new LatLng(place.Latitude, place.Longitude), 15));
                }
            }
            LatLngBounds.Builder builder = new LatLngBounds.Builder();
            foreach (var marker in markers)
            {
                builder.Include(marker.Position);
            }
            LatLngBounds bounds  = builder.Build();
            int          padding = 240; // offset from edges of the map in pixels
            CameraUpdate cu      = CameraUpdateFactory.NewLatLngBounds(bounds, padding);

            Map.AnimateCamera(cu);
        }
        private void ZoomAndCenterMap(IEnumerable <HeritageProperty> items)
        {
            Task.Run(async() =>
            {
                // wait a bit
                await Task.Delay(50);

                // invoke on main thread
                Handler.InvokeOnMainThread(() =>
                {
                    // create a bounds builder
                    LatLngBounds.Builder builder = new LatLngBounds.Builder();

                    // loop all the properties and add them as markers
                    foreach (var item in items)
                    {
                        builder.Include(new LatLng(item.Latitude, item.Longitude));
                    }

                    // zoom the map in
                    CameraUpdate cu = CameraUpdateFactory.NewLatLngBounds(builder.Build(), 100);
                    this.NativeMap.MoveCamera(cu);
                    this.NativeMap.AnimateCamera(cu);
                });
            });
        }
Beispiel #16
0
        private async Task Agregar_marcadores()
        {
            if (GlobalValues.arr_lugares.Count > 0)
            {
                LatLngBounds.Builder         builder = new LatLngBounds.Builder();
                List <Manboss_mandados_ruta> puntos  = new List <Manboss_mandados_ruta>();
                foreach (Lugares aux in GlobalValues.arr_lugares)
                {
                    MarkerOptions markerOpt1 = new MarkerOptions();
                    LatLng        lugar      = new LatLng(aux.Latitud, aux.Longitud);
                    builder.Include(lugar);
                    markerOpt1.SetPosition(lugar);
                    markerOpt1.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.mandado));
                    _map.AddMarker(markerOpt1);
                    Manboss_mandados_ruta posicion = new Manboss_mandados_ruta();
                    posicion.Latitud  = aux.Latitud;
                    posicion.Longitud = aux.Longitud;
                    puntos.Add(posicion);
                }
                //polyline
                await Obtener_direcciones(puntos);

                //Mover camera
                LatLngBounds bounds       = builder.Build();
                CameraUpdate cameraUpdate = CameraUpdateFactory.NewLatLngBounds(bounds, 300);
                _map.MoveCamera(cameraUpdate);
                //Revisar mínimo de ubicaciones
                Lugares primero = GlobalValues.arr_lugares.First();
                if (GlobalValues.arr_lugares.Count >= primero.Min)
                {
                    btn_pagar_mandado.Visibility = ViewStates.Visible;
                }
            }
        }
Beispiel #17
0
        public void OnMapReady(GoogleMap googleMap)
        {
            LatLng latlng = null;

            this.Gmap = googleMap;
            Gmap.UiSettings.ZoomControlsEnabled = true;
            Gmap.UiSettings.ZoomGesturesEnabled = true;

            LatLngBounds.Builder builder = new LatLngBounds.Builder();

            _auditDetailList   = manageTemplate.GetAllAudit();
            _auditTemplateList = manageTemplate.GetTemplates();
            foreach (AuditDetails auditDetail in _auditDetailList)
            {
                string[] gpsCoordinates = auditDetail.GPSCoordinate.Split(',');
                if (gpsCoordinates.Count() > 0)
                {
                    latlng = new LatLng(Convert.ToDouble(gpsCoordinates[0]), Convert.ToDouble(gpsCoordinates[1]));
                    MarkerOptions options         = new MarkerOptions().SetPosition(latlng).SetAlpha(auditDetail.Id);
                    var           templatedetails = _auditTemplateList.Find(t => t.Id == auditDetail.TemplateId);
                    options.SetTitle(templatedetails.Name);
                    options.SetSnippet(auditDetail.Location + " - " + DateTime.Today.ToShortDateString());

                    Gmap.AddMarker(options);
                    builder.Include(latlng);
                }
            }

            LatLngBounds bounds = builder.Build();
            CameraUpdate cu     = CameraUpdateFactory.NewLatLngBounds(bounds, Resources.DisplayMetrics.WidthPixels, Resources.DisplayMetrics.HeightPixels, 120);

            googleMap.MoveCamera(cu);

            Gmap.InfoWindowClick += Gmap_InfoWindowClick;
        }
Beispiel #18
0
        public void OnMapReady(GoogleMap googleMap)
        {
            try
            {
                var markers = new List <MarkerOptions>();
                foreach (var place in ViewModel.Places)
                {
                    var marker = new MarkerOptions();
                    marker.SetPosition(new LatLng(place.Latitude, place.Longitude));
                    marker.SetTitle(place.Name);
                    googleMap.AddMarker(marker);
                    markers.Add(marker);
                }
                if (markers.Count == 0)
                {
                    return;
                }
                var builder = new LatLngBounds.Builder();

                foreach (var marker in markers)
                {
                    builder.Include(marker.Position);
                }

                LatLngBounds bounds  = builder.Build();
                int          padding = 145; // offset from edges of the map in pixels
                var          cu      = CameraUpdateFactory.NewLatLngBounds(bounds, padding);
                googleMap.AnimateCamera(cu);
            }
            catch (Exception e)
            {
                App.LogOutLn(e.StackTrace, GetType().Name);
            }
        }
Beispiel #19
0
        public bool OnClusterClick(ICluster cluster)
        {
            // Show a toast with some info when the cluster is clicked.
            while (cluster.Items.GetEnumerator().MoveNext())
            {
                var person = cluster.Items.GetEnumerator().Current as Person;
                Toast.MakeText(this, cluster.Size + "(including " + person.name + ")", ToastLength.Short).Show();
            }

            // Zoom in the cluster. Need to create LatLngBounds and including all the cluster items
            // inside of bounds, then animate to center of the bounds.

            // Create the builder to collect all essential cluster items for the bounds.
            LatLngBounds.Builder builder = new LatLngBounds.Builder();
            foreach (IClusterItem item in cluster.Items)
            {
                builder.Include(item.Position);
            }
            // Get the LatLngBounds
            LatLngBounds bounds = builder.Build();

            // Animate camera to the bounds
            try
            {
                getMap().AnimateCamera(CameraUpdateFactory.NewLatLngBounds(bounds, 100));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }

            return(true);
        }
Beispiel #20
0
        private async void GetRutas(int id_mandado)
        {
            List <Manboss_mandados_ruta> rutas = await core.GetRutas(id_mandado);

            LatLngBounds.Builder builder = new LatLngBounds.Builder();
            foreach (Manboss_mandados_ruta ruta in rutas)
            {
                markerOpt1 = new MarkerOptions();
                LatLng lugar = new LatLng(ruta.Latitud, ruta.Longitud);
                builder.Include(lugar);
                markerOpt1.SetPosition(lugar);
                markerOpt1.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.mandado));
                _map.AddMarker(markerOpt1);
            }
            //Mover camera
            LatLngBounds bounds       = builder.Build();
            CameraUpdate cameraUpdate = CameraUpdateFactory.NewLatLngBounds(bounds, 300);

            _map.MoveCamera(cameraUpdate);
            //Dibujar ruta
            List <Manboss_repartidores_ubicaciones> ubicaciones = await core.GetUbicaciones(id_mandado);

            var polylineOptions = new PolylineOptions();

            polylineOptions.InvokeColor(0x6604B7FF);
            foreach (var position in rutas)
            {
                polylineOptions.Add(new LatLng(position.Latitud, position.Longitud));
            }
            foreach (var position in ubicaciones)
            {
                polylineOptions.Add(new LatLng(position.latitud, position.longitud));
            }
            _map.AddPolyline(polylineOptions);
        }
Beispiel #21
0
        public void OnMapReady(GoogleMap googleMap)
        {
            map = googleMap;
            var options = new TileOverlayOptions();

            options.InvokeTileProvider(new CustomTileProvider(0));

            map.MapType = GoogleMap.MapTypeNone;
            map.AddTileOverlay(options);
            map.SetOnMarkerClickListener(this);

            map.UiSettings.ZoomControlsEnabled = true;
            map.SetMaxZoomPreference(18);

            map.AddMarker(new MarkerOptions().SetPosition(new LatLng(-27.47093, 153.0235)).SetTitle("HOME"));

            GeoCode mGeoCode = new GeoCode("Тюмень, ул. Широтная, д. 158, к. 1");

            mGeoCode.Complited += (pos, lowerCorner, upperCorner) =>
            {
                RunOnUiThread(() =>
                {
                    map.AddMarker(new MarkerOptions().SetPosition(pos).SetTitle("HOME"));
                    map.MoveCamera(CameraUpdateFactory.NewLatLngBounds(new LatLngBounds(lowerCorner, upperCorner), 0));
                });
            };
            mGeoCode.Error += e =>
            {
                Toast.MakeText(this, e.ToString(), ToastLength.Short).Show();
            };
        }
Beispiel #22
0
        private void DrawMarkers(TripDetails tripDetail)
        {
            // Draw Markers
            string[] origin      = tripDetail.originLatLng.Split(',');
            string[] destination = tripDetail.destinationLatLng.Split(',');
            LatLng   o           = new LatLng(double.Parse(origin[0]), double.Parse(origin[1]));
            LatLng   d           = new LatLng(double.Parse(destination[0]), double.Parse(destination[1]));

            mMap.AddMarker(new MarkerOptions().SetPosition(o).SetTitle("Origin"));
            mMap.AddMarker(new MarkerOptions().SetPosition(d).SetTitle("Destination"));
            if (tripDetail.TripPassengers != null)
            {
                foreach (TripPassenger tp in tripDetail.TripPassengers)
                {
                    string[] w        = tp.originLatLng.Split(',');
                    LatLng   waypoint = new LatLng(double.Parse(w[0]), double.Parse(w[1]));
                    mMap.AddMarker(new MarkerOptions().SetPosition(waypoint).SetTitle("waypoint"));
                }
            }
            // Zoom map to the set padding
            LatLngBounds.Builder builder = new LatLngBounds.Builder();
            builder.Include(o);
            builder.Include(d);
            LatLngBounds bounds  = builder.Build();
            int          padding = 100;
            CameraUpdate cu      = CameraUpdateFactory.NewLatLngBounds(bounds, padding);

            mMap.AnimateCamera(cu);
        }
Beispiel #23
0
        void MoveToRegion(MapSpan span, bool animate)
        {
            GoogleMap map = NativeMap;

            if (map == null)
            {
                return;
            }

            span = span.ClampLatitude(85, -85);
            var ne = new LatLng(span.Center.Latitude + span.LatitudeDegrees / 2,
                                span.Center.Longitude + span.LongitudeDegrees / 2);
            var sw = new LatLng(span.Center.Latitude - span.LatitudeDegrees / 2,
                                span.Center.Longitude - span.LongitudeDegrees / 2);
            CameraUpdate update = CameraUpdateFactory.NewLatLngBounds(new LatLngBounds(sw, ne), 0);

            try
            {
                if (animate)
                {
                    map.AnimateCamera(update);
                }
                else
                {
                    map.MoveCamera(update);
                }
            }
            catch (IllegalStateException exc)
            {
                Application.Current?.FindMauiContext()?.CreateLogger <MapRenderer>()?.LogWarning(exc, $"MoveToRegion exception");
            }
        }
        private void SetPointsBounds(List <LatLng> points)
        {
            LatLngBounds.Builder builder;
            float scale   = ApplicationContext.Resources.DisplayMetrics.Density;
            int   padding = (int)(40 * scale + 0.5f);

            builder = new LatLngBounds.Builder();

            //foreach (Marker marker in markers)
            //{
            //    builder.Include(marker.Position);
            //}

            Double minLatitude  = 0;
            Double minLongitude = 0;
            Double maxLatitude  = 0;
            Double maxLongitude = 0;

            foreach (var point in points)
            {
                if (minLatitude == 0.0f)
                {                 // No matter on wich var we check
                    minLatitude  = point.Latitude;
                    minLongitude = point.Longitude;
                    maxLatitude  = point.Latitude;
                    maxLongitude = point.Longitude;
                }
                else
                {
                    if (point.Latitude < minLatitude)
                    {
                        minLatitude = point.Latitude;
                    }
                    if (point.Latitude > maxLatitude)
                    {
                        maxLatitude = point.Latitude;
                    }
                    if (point.Longitude < minLongitude)
                    {
                        minLongitude = point.Longitude;
                    }
                    if (point.Longitude > maxLongitude)
                    {
                        maxLongitude = point.Longitude;
                    }
                }
            }

            builder.Include(new LatLng(minLatitude, minLongitude));
            builder.Include(new LatLng(maxLatitude, maxLongitude));

            LatLngBounds bounds = builder.Build();
            CameraUpdate cu     = CameraUpdateFactory.NewLatLngBounds(bounds, padding);

            _GoogleMap.AnimateCamera(cu, 800, null);
        }
        public void OnClick(View v)
        {
            if (hMap == null)
            {
                Log.Warn(TAG, "map is null");
                return;
            }
            if (v.Id == Resource.Id.animateCamera)
            {
                CameraUpdate cameraUpdate = CameraUpdateFactory.NewLatLng(new LatLng(20, 120));
                Toast.MakeText(this, hMap.CameraPosition.Target.ToString(), ToastLength.Long).Show();
                hMap.AnimateCamera(cameraUpdate);
            }
            if (v.Id == Resource.Id.getCameraPosition)
            {
                CameraPosition position = hMap.CameraPosition;
                Toast.MakeText(ApplicationContext, position.ToString(), ToastLength.Long).Show();

                // Displays the maximum zoom level and minimum scaling level of the current camera.
                Log.Info(TAG, position.ToString());
                Log.Info(TAG, "MaxZoomLevel:" + hMap.MaxZoomLevel + " MinZoomLevel:" + hMap.MinZoomLevel);
            }
            if (v.Id == Resource.Id.moveCamera)
            {
                CameraPosition build        = new CameraPosition.Builder().Target(new LatLng(60, 60)).Build();
                CameraUpdate   cameraUpdate = CameraUpdateFactory.NewCameraPosition(build);
                Toast.MakeText(this, hMap.CameraPosition.ToString(), ToastLength.Long).Show();
                hMap.MoveCamera(cameraUpdate);
            }
            if (v.Id == Resource.Id.ZoomBy)
            {
                CameraUpdate cameraUpdate = CameraUpdateFactory.ZoomBy(2);
                Toast.MakeText(this, "amount = 2", ToastLength.Long).Show();
                hMap.MoveCamera(cameraUpdate);
            }
            if (v.Id == Resource.Id.newLatLngBounds)
            {
                LatLng       southwest    = new LatLng(30, 60);
                LatLng       northeast    = new LatLng(60, 120);
                LatLngBounds latLngBounds = new LatLngBounds(southwest, northeast);
                Toast.MakeText(this, "southwest =" + southwest.ToString() + " northeast=" + northeast.ToString() + " padding=2",
                               ToastLength.Long).Show();
                CameraUpdate cameraUpdate = CameraUpdateFactory.NewLatLngBounds(latLngBounds, 2);
                hMap.MoveCamera(cameraUpdate);
            }
            if (v.Id == Resource.Id.setCameraPosition)
            {
                LatLng         southwest      = new LatLng(30, 60);
                CameraPosition cameraPosition =
                    new CameraPosition.Builder().Target(southwest).Zoom(10).Bearing(2.0f).Tilt(2.5f).Build();
                Toast.MakeText(this, cameraPosition.ToString(), ToastLength.Long).Show();
                CameraUpdate cameraUpdate = CameraUpdateFactory.NewCameraPosition(cameraPosition);
                hMap.MoveCamera(cameraUpdate);
            }
        }
        private void SetZoom(IEnumerable <CoordinateViewModel> addresseesToDisplay)
        {
            var coordinateViewModels = addresseesToDisplay as CoordinateViewModel[] ?? addresseesToDisplay.SelectOrDefault(addresses => addresses.ToArray(), new CoordinateViewModel[0]);

            if (!coordinateViewModels.Any())
            {
                return;
            }


            // We should not trigger the camera change event since this is an automated camera change.
            _bypassCameraChangeEvent = true;

            if (coordinateViewModels.Length == 1)
            {
                var lat = coordinateViewModels[0].Coordinate.Latitude;
                var lon = coordinateViewModels[0].Coordinate.Longitude;

                if (coordinateViewModels[0].Zoom != ZoomLevel.DontChange)
                {
                    MoveCameraTo(lat, lon, 16);
                }
                else
                {
                    MoveCameraTo(lat, lon);
                }
                return;
            }

            double minLat = 90;
            double maxLat = -90;
            double minLon = 180;
            double maxLon = -180;

            foreach (var item in coordinateViewModels)
            {
                var lat = item.Coordinate.Latitude;
                var lon = item.Coordinate.Longitude;
                maxLat = Math.Max(lat, maxLat);
                minLat = Math.Min(lat, minLat);
                maxLon = Math.Max(lon, maxLon);
                minLon = Math.Min(lon, minLon);
            }

            var overlayOffset = OverlayOffsetProvider != null
                ? OverlayOffsetProvider() + _pickupOverlay.Height
                : 0;

            Map.AnimateCamera(CameraUpdateFactory.NewLatLngBounds(new LatLngBounds(new LatLng(minLat, minLon), new LatLng(maxLat, maxLon)), TouchableMap.View.Width, TouchableMap.View.Height - overlayOffset, DrawHelper.ToPixels(50)));

            overlayOffset = (TouchableMap.View.Height / 2) - (((TouchableMap.View.Height - overlayOffset) / 2) + overlayOffset);

            animateLatLngZoom(Map.CameraPosition.Target, 0, overlayOffset);
        }
        private async void BuildMap(string[] addressString)
        {
            MapFragment mapFrag = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map);
            GoogleMap   map     = mapFrag.Map;

            if (map != null)
            {
                map.MoveCamera(CameraUpdateFactory.NewLatLng(new LatLng(0, 0)));
            }

            List <MarkerOptions> markers = new List <MarkerOptions>();

            if (addressString.Length != 0)
            {
                var locations = await PlaceBLL.Instance.GetLocationFromAddress(this, 1, addressString);

                if (locations != null && locations.Count > 0)
                {
                    var i = 0;
                    foreach (var loc in locations)
                    {
                        markers.Add(BuildMarkerFromLocation(loc, addressString[i]));
                        i++;
                    }
                }
            }

            this.RunOnUiThread(() =>
            {
                if (map != null && markers != null && markers.Count > 0)
                {
                    foreach (var mark in markers)
                    {
                        map.AddMarker(mark);
                    }

                    if (markers.Count == 1)
                    {
                        CameraPosition.Builder builder = CameraPosition.InvokeBuilder();
                        builder.Target(markers.ElementAt(0).Position);
                        builder.Zoom(14);
                        CameraPosition cameraPosition = builder.Build();
                        CameraUpdate cameraUpdate     = CameraUpdateFactory.NewCameraPosition(cameraPosition);
                        map.MoveCamera(cameraUpdate);
                    }
                    else
                    {
                        map.MoveCamera(CameraUpdateFactory.NewLatLngBounds(GetBoundsForMap(markers), 250, 250, 0));
                    }
                }
            });
        }
Beispiel #28
0
        private static void AddMarker(GoogleMap _map, LatLng location)
        {
            _map.Clear();
            var icon = BitmapDescriptorFactory.FromResource(Resource.Drawable.map_marker_icon);

            _map.AddMarker(new MarkerOptions().SetPosition(location).Draggable(true).SetAlpha(0.7f).SetIcon(icon));
            LatLngBounds.Builder builder = new LatLngBounds.Builder();
            builder.Include(location);
            LatLngBounds bounds       = builder.Build();
            CameraUpdate cameraUpdate = CameraUpdateFactory.NewLatLngBounds(bounds, 40, 40, 3);

            _map.AnimateCamera(cameraUpdate);
        }
Beispiel #29
0
        public void OnMapLoaded()
        {
            LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder();
            foreach (RouteSegment segment in routeSegments)
            {
                boundsBuilder.Include(new LatLng(segment.From.Stop.Position.Latitude, segment.From.Stop.Position.Longitude));
                boundsBuilder.Include(new LatLng(segment.To.Stop.Position.Latitude, segment.To.Stop.Position.Longitude));
            }

            CameraUpdate cameraUpdate = CameraUpdateFactory.NewLatLngBounds(boundsBuilder.Build(), (int)(Density * 30));

            googleMap.MoveCamera(cameraUpdate);
        }
Beispiel #30
0
        private void UpdateRegion()
        {
            UpdateGoogleMap(formsMap =>
            {
                if (MapEx.Region == null)
                {
                    return;
                }

                var cameraUpdate = CameraUpdateFactory.NewLatLngBounds(MapEx.Region.ToLatLngBounds(), 0);
                NativeMap.MoveCamera(cameraUpdate);
            });
        }