Example #1
0
        public Task <OfflineRegionDto> CreateOfflineRegion(LatLngBoundsDto bounds, int zoomLevel = 8)
        {
            var tcs = new TaskCompletionSource <OfflineRegionDto>();

            LatLngBounds latLngBounds = new LatLngBounds.Builder()
                                        .Include(new LatLng(bounds.Ne.Latitude, bounds.Ne.Longitude))
                                        .Include(new LatLng(bounds.Sw.Latitude, bounds.Sw.Longitude))
                                        .Build();

            var offlineDefinition = new OfflineTilePyramidRegionDefinition(Style.MapboxStreets, latLngBounds, 1,
                                                                           zoomLevel,
                                                                           Application.Context.Resources.DisplayMetrics.Density);

            var jsonObject = new JSONObject();

            jsonObject.Put("REGION_NAME", "Chennai");
            string json = jsonObject.ToString();

            byte[] metadata = Encoding.UTF8.GetBytes(json);

            _offlineManager.CreateOfflineRegion(offlineDefinition, metadata,
                                                new CreateOfflineRegionCallback(Application.Context)
            {
                OnListCallback = region =>
                {
                    region.SetDownloadState(OfflineRegion.StateActive);
                    tcs.SetResult(Transform(region));
                },
                OnErrorCallback = error => { tcs.SetResult(null); }
            });

            return(tcs.Task);
        }
Example #2
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;
        }
Example #3
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);
            }
        }
Example #4
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);
        }
Example #5
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);
        }
Example #6
0
        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));
            }
        }
Example #7
0
        public void BoundCameraToRoute()
        {
            if (route != null)
            {
                var           routeCoords = LineString.FromPolyline(route.Geometry(), Mapbox.Core.Constants.Constants.Precision6).Coordinates();
                List <LatLng> bboxPoints  = new List <LatLng>();

                foreach (var point in routeCoords)
                {
                    bboxPoints.Add(new LatLng(point.Latitude(), point.Longitude()));
                }

                if (bboxPoints.Count > 1)
                {
                    try
                    {
                        var bounds = new LatLngBounds.Builder().Includes(bboxPoints).Build();
                        // left, top, right, bottom
                        int topPadding = launchBtnFrame.Height * 2;
                        AnimateCameraBbox(bounds, CAMERA_ANIMATION_DURATION, new int[] { 50, topPadding, 50, 100 });
                    }
                    catch (InvalidLatLngBoundsException ex)
                    {
                        Toast.MakeText(this, Resource.String.error_valid_route_not_found, ToastLength.Short).Show();
                    }
                }
            }
        }
Example #8
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;
                }
            }
        }
Example #9
0
        public static Community IsInCyclesCommunity(LatLng pointLatLng)
        {
            var builder = new LatLngBounds.Builder();

            if (CyclesCommunities == null)
            {
                return(null);
            }
            foreach (Community community in CyclesCommunities)
            {
                if (community == null)
                {
                    continue;
                }
                foreach (LatLng latLngSet in community.PolygonCoordinates)
                {
                    if (latLngSet != null)
                    {
                        builder.Include(latLngSet);
                    }
                }

                LatLngBounds polygonBounds = builder.Build();
                if (polygonBounds.Contains(pointLatLng))
                {
                    return(community);
                }
            }

            return(null);
        }
Example #10
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);
        }
Example #11
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);
        }
Example #12
0
        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));
        }
        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);
                });
            });
        }
Example #14
0
        public void Refresh(List <Option> points)
        {
            this.mapView.Map.Clear();
            LatLngBounds.Builder builder = new LatLngBounds.Builder();
            foreach (var point in points)
            {
                var latLng = new LatLng(point.Lat, point.Lng);
                builder = builder.Include(latLng);
                BitmapDescriptor bitmap = BitmapDescriptorFactory.FromResource(Resource.Drawable.red_location);
                //构建MarkerOption,用于在地图上添加Marker
                OverlayOptions option = new MarkerOptions()
                                        .InvokePosition(latLng)
                                        .InvokeTitle(point.Title)
                                        .Anchor(0.5f, 0.5f)
                                        .Draggable(true)
                                        .ScaleX(0.5f)
                                        .ScaleY(0.5f)
                                        .InvokeIcon(bitmap);

                ////在地图上添加Marker,并显示
                this.mapView.Map.AddOverlay(option);
            }

            LatLngBounds    latlngBounds = builder.Build();
            MapStatusUpdate u            = MapStatusUpdateFactory.NewLatLngBounds(latlngBounds, mapView.Width, mapView.Height);

            mapView.Map.AnimateMapStatus(u);
        }
Example #15
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);
        }
Example #16
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 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);
        }
Example #18
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);
        }
Example #19
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);
            }
        }
        public Task <OfflinePack> DownloadMap(OfflinePackRegion region, Dictionary <string, string> packInfo)
        {
            var tcs          = new TaskCompletionSource <OfflinePack>();
            var latLngBounds = new LatLngBounds.Builder()
                               .Include(region.Bounds.NorthEast.ToLatLng())                          // Northeast
                               .Include(region.Bounds.SouthWest.ToLatLng())                          // Southwest
                               .Build();
            var definition = new OfflineTilePyramidRegionDefinition(
                region.StyleURL,
                latLngBounds,
                region.MinimumZoomLevel,
                region.MaximumZoomLevel,
                Android.App.Application.Context.Resources.DisplayMetrics.Density);

            byte[] metadata = null;
            if (packInfo != null)
            {
                //var binFormatter = new BinaryFormatter();
                //var mStream = new MemoryStream();
                //binFormatter.Serialize(mStream, packInfo);
                //metadata = mStream.ToArray();
                try
                {
                    var jsonObject = new JsonObject();

                    foreach (KeyValuePair <string, string> pair in packInfo)
                    {
                        jsonObject.AddProperty(pair.Key, pair.Value);
                    }
                    var json = new Java.Lang.String(jsonObject.ToString());
                    metadata = json.GetBytes(JSON_CHARSET);
                    System.Diagnostics.Debug.WriteLine("Encoding metadata succeeded: " + metadata.Length.ToString());
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Failed to encode metadata: " + ex.Message);
                }
            }

            offlineManager.CreateOfflineRegion(
                definition,
                metadata,
                new CreateOfflineRegionCallback(
                    (reg) =>
            {
                reg.SetDownloadState(OfflineRegion.StateActive);
                tcs.TrySetResult(reg.ToFormsPack());
            },
                    (msg) =>
            {
                System.Diagnostics.Debug.WriteLine("[ERROR] Couldn't create offline pack: " + msg);
                tcs.TrySetResult(null);
            }
                    )
                );

            return(tcs.Task);
        }
        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);
        }
Example #22
0
        public void updateMapPerspective(ICameraPerspective cameraPerspective)
        {
            if (nMap == null)
            {
                return;
            }

            if (cameraPerspective is CenterAndZoomCameraPerspective centerAndZoom)
            {
                var camera = CameraUpdateFactory.NewLatLngZoom(centerAndZoom.position.toNativeLatLng(), centerAndZoom.zoomLevel);
                if (centerAndZoom.isAnimated)
                {
                    nMap.AnimateCamera(camera);
                }
                else
                {
                    nMap.MoveCamera(camera);
                }
            }
            else if (cameraPerspective is CoordinatesAndPaddingCameraPerspective span)
            {
                var density = Resources.DisplayMetrics.Density;
                var list    = span.positions.Select((Position p) => new LatLng(p.latitude, p.longitude));
                var builder = new LatLngBounds.Builder();
                builder.Includes(list.ToList());

                var camera = nMap.GetCameraForLatLngBounds(
                    builder.Build(),
                    new int[] {
                    (int)(span.padding.Left * density),
                    (int)(span.padding.Top * density),
                    (int)(span.padding.Right * density),
                    (int)(span.padding.Bottom * density)
                });

                if (span.isAnimated)
                {
                    nMap.AnimateCamera(CameraUpdateFactory.NewCameraPosition(camera));
                }
                else
                {
                    nMap.MoveCamera(CameraUpdateFactory.NewCameraPosition(camera));
                }
            }
            else if (cameraPerspective is CoordinateCameraPerspective center)
            {
                if (center.isAnimated)
                {
                    nMap.AnimateCamera(CameraUpdateFactory.NewLatLng(center.position.toNativeLatLng()));
                }
                else
                {
                    nMap.MoveCamera(CameraUpdateFactory.NewLatLng(center.position.toNativeLatLng()));
                }
            }
        }
Example #23
0
        private void FitAllMarkers(List <LatLng> markerslocations)
        {
            LatLngBounds.Builder builder = new LatLngBounds.Builder();
            foreach (LatLng item in markerslocations)
            {
                builder.Include(item);
            }

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

            _map.AnimateCamera(cu);
        }
Example #24
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);
        }
Example #25
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);
        }
Example #26
0
 private void BitmapOverLay()
 {
     // 设置当前地图显示为北京市恭王府
     aMap.MoveCamera(CameraUpdateFactory.NewLatLngZoom(new LatLng(39.936713, 116.386475), 19));
     //设置图片的显示区域。
     var bounds = new LatLngBounds.Builder()
                  .Include(new LatLng(39.935029, 116.384377))
                  .Include(new LatLng(39.949577, 116.398331)).Build();
     var groundoverlay = aMap.AddGroundOverlay(new GroundOverlayOptions()
                                               .Anchor(0.5f, 0.5f).InvokeTransparency(0.1f)
                                               .InvokeImage(BitmapDescriptorFactory.FromResource(Resource.Drawable.dashboard_queue_text))
                                               .PositionFromBounds(bounds));
 }
        protected void ZoomToAll()
        {
            if (MarkerSet?.MarkerWrappers?.Any() ?? false)
            {
                var boundsBuilder = new LatLngBounds.Builder();
                foreach (var markerWrapper in MarkerSet.MarkerWrappers)
                {
                    boundsBuilder.Include(markerWrapper.Position);
                }

                var bounds = CameraUpdateFactory.NewLatLngBounds(boundsBuilder.Build(), (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 70, Context.Resources.DisplayMetrics));
                Map.AnimateCamera(bounds);
            }
        }
        private async void LoadMap(bool loadTripInfo)
        {
            mMap.Clear();

            RunOnUiThread(() =>
            {
                progress.Show();
            });

            LatLngBounds.Builder builder = new LatLngBounds.Builder();
            builder.Include(originLatLng);
            builder.Include(destLatLng);
            LatLngBounds bounds = builder.Build();

            int          padding = 100; // offset from edges of the map in pixels
            CameraUpdate cu      = CameraUpdateFactory.NewLatLngBounds(bounds, padding);

            // Add markers to oriign and destination
            mMap.AddMarker(new MarkerOptions().SetPosition(originLatLng).SetTitle("Origin"));
            mMap.AddMarker(new MarkerOptions().SetPosition(destLatLng).SetTitle("Destination"));

            // Combine Google Direction API string
            string urlGoogleDirection = MapHelper.GoogleDirectionAPIAddress(originLatLng.Latitude + "," + originLatLng.Longitude,
                                                                            destLatLng.Latitude + "," + destLatLng.Longitude);
            string strGoogleDirection = await MapHelper.DownloadStringAsync(urlGoogleDirection);

            var googleDirectionAPIRoute = JsonConvert.DeserializeObject <GoogleDirectionAPI>(strGoogleDirection);

            string encodedPoints    = googleDirectionAPIRoute.routes[0].overview_polyline.points;
            var    lstDecodedPoints = MapHelper.DecodePolylinePoint(encodedPoints);
            //convert list of location point to array of latlng type

            var latLngPoints   = lstDecodedPoints.ToArray();
            var polylineoption = new PolylineOptions();

            polylineoption.InvokeColor(Android.Graphics.Color.SkyBlue);
            polylineoption.Geodesic(true);
            polylineoption.Add(latLngPoints);
            mMap.AddPolyline(polylineoption);
            mMap.AnimateCamera(cu);

            if (loadTripInfo)
            {
                LoadTripInformation();
            }
            RunOnUiThread(() =>
            {
                progress.Dismiss();
            });
        }
Example #29
0
 /// <summary>
 /// Fields the selected.
 /// </summary>
 /// <param name="sender">Sender object.</param>
 /// <param name="e">E event.</param>
 public void FieldSelected(object sender, FieldSelectedEventArgs e)
 {
     if (this.Map != null)
     {
         var    builder = new LatLngBounds.Builder();
         var    whc     = GeoHelper.CalculateBoundingBox(e.Field.BoundingCoordinates);
         double width   = whc.Width * 0.95;
         double height  = whc.Height * 0.59;
         builder.Include(new LatLng(whc.Center.Latitude - width, whc.Center.Longitude - height));
         builder.Include(new LatLng(whc.Center.Latitude + width, whc.Center.Longitude + height));
         var bounds = builder.Build();
         this.Map.MoveCamera(CameraUpdateFactory.NewLatLngBounds(bounds, 0));
     }
 }
Example #30
0
        /// <summary>
        /// Creates a <see cref="LatLngBounds"/> from a collection of <see cref="MapSpan"/>
        /// </summary>
        /// <param name="spans">The spans to get calculate the bounds from</param>
        /// <returns>The bounds</returns>
        private LatLngBounds BoundsFromMapSpans(params MapSpan[] spans)
        {
            LatLngBounds.Builder builder = new LatLngBounds.Builder();

            foreach (var region in spans)
            {
                builder
                .Include(GmsSphericalUtil.ComputeOffset(region.Center, region.Radius.Meters, 0).ToLatLng())
                .Include(GmsSphericalUtil.ComputeOffset(region.Center, region.Radius.Meters, 90).ToLatLng())
                .Include(GmsSphericalUtil.ComputeOffset(region.Center, region.Radius.Meters, 180).ToLatLng())
                .Include(GmsSphericalUtil.ComputeOffset(region.Center, region.Radius.Meters, 270).ToLatLng());
            }
            return(builder.Build());
        }