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 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); }
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; }
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); } }
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); } }
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); }
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); }
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); }
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)); } }
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 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); }
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); }
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); }
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); }); }); }
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; } } }
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 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())); } } }
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); }
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); }
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); }
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); } }
/// <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)); } }
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(); }); }
/// <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()); }
///<inheritdoc/> public void FitMapRegionToPositions(IEnumerable <Position> positions, bool animate = false) { if (this._googleMap == null) { throw new InvalidOperationException("Map not ready"); } if (positions == null) { throw new InvalidOperationException("positions can't be null"); } LatLngBounds.Builder builder = new LatLngBounds.Builder(); positions.ToList().ForEach(i => builder.Include(i.ToLatLng())); if (animate) { this._googleMap.AnimateCamera(CameraUpdateFactory.NewLatLngBounds(builder.Build(), 30)); } else { this._googleMap.MoveCamera(CameraUpdateFactory.NewLatLngBounds(builder.Build(), 30)); } }
public void OnMapLoaded() { // Compute global line bounds to initialize camera LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder(); foreach (Route route in line.Routes) { foreach (Step step in route.Steps) { boundsBuilder.Include(new LatLng(step.Stop.Position.Latitude, step.Stop.Position.Longitude)); } } CameraUpdate cameraUpdate = CameraUpdateFactory.NewLatLngBounds(boundsBuilder.Build(), 100); googleMap.MoveCamera(cameraUpdate); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.showMap); var mapFragment = (SupportMapFragment)SupportFragmentManager.FindFragmentById(Resource.Id.map); mapFragment.GetMapAsync(this); LatLngBounds.Builder b = new LatLngBounds.Builder(); for (var j = 0; j < helloMap.hellolats.Length; j++) { b.Include(new LatLng(helloMap.hellolats[j], helloMap.hellolons[j])); } bounds = b.Build(); cu = CameraUpdateFactory.NewLatLngBounds(bounds, 50, 50, 10); }
/// <summary> /// Updates location pins on the map. /// </summary> async void UpdateLocations() { if (googleMap == null) { return; } googleMap.Clear(); try { MapsInitializer.Initialize(this); } catch (GooglePlayServicesNotAvailableException e) { Console.WriteLine("Google Play Services not available:" + e); return; } await assignmentViewModel.LoadAssignmentsAsync(); var points = new LatLngBounds.Builder(); foreach (var assignment in assignmentViewModel.Assignments) { var markerOptions = GetMarkerOptionsForAssignment(assignment); googleMap.AddMarker(markerOptions); points.Include(markerOptions.Position); } if (assignmentViewModel.ActiveAssignment != null) { var markerOptions = GetMarkerOptionsForAssignment(assignmentViewModel.ActiveAssignment); googleMap.AddMarker(markerOptions).ShowInfoWindow(); points.Include(markerOptions.Position); googleMap.CameraPosition.Target = markerOptions.Position; } var bounds = points.Build(); if (mapView.Width == 0) { initTry = 0; PostDelayInitMap(bounds); } else { googleMap.MoveCamera(CameraUpdateFactory.NewLatLngBounds(bounds, 0)); } }
public void AnimateCameraBounds(Point[] points) { if (IsMapNull) { return; } var builder = new LatLngBounds.Builder(); foreach (var p in points) { builder.Include(new LatLng(p.Lat, p.Lng)); } var bounds = builder.Build(); var cameraUpdate = CameraUpdateFactory.NewLatLngBounds(bounds, 80); Map.AnimateCamera(cameraUpdate); }
public static Community IsInCyclesCommunity(Location location) { var builder = new LatLngBounds.Builder(); if (CyclesCommunities == null) { return(null); } if (CyclesCommunitiesPolygons != null && CyclesCommunitiesPolygons.Any()) { foreach (LatLngBounds polygonBounds in CyclesCommunitiesPolygons) { if (polygonBounds.Contains(new LatLng(location.Latitude, location.Longitude))) { return(CyclesCommunities[CyclesCommunitiesPolygons.IndexOf(polygonBounds)]); } } } else { 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(); CyclesCommunitiesPolygons?.Add(polygonBounds); if (polygonBounds.Contains(new LatLng(location.Latitude, location.Longitude))) { return(community); } } } return(null); }