@Override public boolean onClusterClick(Cluster<Person> cluster) { // Show a toast with some info when the cluster is clicked. String firstName = cluster.getItems().iterator().next().name; Toast.makeText(this, cluster.getSize() + " (including " + firstName + ")", Toast.LENGTH_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 = LatLngBounds.builder(); for (ClusterItem item : cluster.getItems()) { builder.include(item.getPosition()); } // Get the LatLngBounds final LatLngBounds bounds = builder.build(); // Animate camera to the bounds try { getMap().animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100)); } catch (Exception e) { e.printStackTrace(); } return true; }
private void displayPlacesOnMap(List<Place> places) { if (map != null) { map.clear(); if (!places.isEmpty()) { LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder(); for (Place place : places) { // Creates a marker at the place location and with the place name LatLng position = place.getPosition(); String placeName = place.get(Place.NAME); if (position != null) { MarkerOptions markerOptions = new MarkerOptions() .position(position) .title(placeName); Marker marker = map.addMarker(markerOptions); marker.setTag(place); boundsBuilder.include(position); } } CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(boundsBuilder.build(), 100); map.moveCamera(cameraUpdate); } } }
private void drawPolyLineAndAnimateCar() { LatLngBounds.Builder builder = new LatLngBounds.Builder(); for (LatLng latLng : polyLineList) { builder.include(latLng); LatLngBounds bounds = builder.build(); CameraUpdate mCameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds, 2); mMap.animateCamera(mCameraUpdate);
@Override public void onMapLoaded() { int count = 0; LatLngBounds.Builder builder = new LatLngBounds.Builder(); for (ExtraMarker extraMarker : viewOption.getMarkers()) { count++; builder.include(extraMarker.getCenter()); BitmapDescriptor icon = BitmapDescriptorFactory.fromBitmap(getBitmapFromDrawable(context, extraMarker.getIcon())); googleMap.addMarker( ); for (LatLng latLng : polygon.getPoints()) { builder.include(latLng); ); for (LatLng latLng : polyline.getPoints()) { builder.include(latLng);
LatLngBounds area = new LatLngBounds.Builder() .include(mOrigem) .include(mDestino) .build(); mGoogleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(area, 50)); } else {
LatLngBounds.Builder builder = new LatLngBounds.Builder(); for (LatLng latLng : latLngs) { builder.include(latLng); LatLngBounds bounds = builder.build(); CameraUpdate mCameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds, 2); mMap.animateCamera(mCameraUpdate); marker.setRotation(getBearing(latLngs.get(0), newPos)); mMap.animateCamera(CameraUpdateFactory.newCameraPosition (new CameraPosition.Builder().target(newPos) .zoom(15.5f).build()));
LatLngBounds.Builder builder = new LatLngBounds.Builder(); for(Marker marker : markers) { builder.include(marker.getPosition()); LatLngBounds bounds = builder.build();
public static void moveCameraToKml(KmlLayer kmlLayer, GoogleMap googleMap) { //TODO fixed error with some kml file https://developers.google.com/maps/documentation/android-api/utility/kml //Only use in this kml file correctly. LatLngBounds.Builder builder = new LatLngBounds.Builder(); KmlContainer container = kmlLayer.getContainers().iterator().next(); container = container.getContainers().iterator().next(); KmlPlacemark placemark = container.getPlacemarks().iterator().next(); KmlPolygon polygon = (KmlPolygon) placemark.getGeometry(); for (LatLng latLng : polygon.getOuterBoundaryCoordinates()) { builder.include(latLng); } googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 50)); } }
@Override public void onInfoWindowClick(Marker marker) { if (marker.isCluster()) { List<Marker> markers = marker.getMarkers(); Builder builder = LatLngBounds.builder(); for (Marker m : markers) { builder.include(m.getPosition()); } LatLngBounds bounds = builder.build(); map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, getResources().getDimensionPixelSize(R.dimen.padding))); } } });
/** * Creates a new builder. */ public Builder builder() { return new Builder(); }
public void zoomToTwoPoints(LatLng pointA, LatLng pointB) { if ((pointA.latitude != pointB.latitude) && (pointA.longitude != pointB.longitude)) { LatLngBounds.Builder boundsCreator = LatLngBounds.builder(); boundsCreator.include(pointA); boundsCreator.include(pointB); mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(boundsCreator.build(), getResources().getInteger(R.integer.route_zoom_padding))); } }
mMap.addMarker(new MarkerOptions().position(fromPosition).title(start_address)); mMap.addMarker(new MarkerOptions().position(toPosition).title(end_address)); com.google.android.gms.maps.model.LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder(); boundsBuilder.include(fromPosition); boundsBuilder.include(toPosition); final LatLngBounds bounds = boundsBuilder.build(); mMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() { @Override public void onMapLoaded() { mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 12)); } });
public static void fixZoomForLatLngs(GoogleMap googleMap, List<LatLng> latLngs) { if (latLngs!=null && latLngs.size() > 0) { LatLngBounds.Builder bc = new LatLngBounds.Builder(); for (LatLng latLng: latLngs) { bc.include(latLng); } googleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bc.build(), 50),4000,null); } }
public static LatLngBounds fromCenterAndPositions(LatLng center, Iterable<LatLng> positions) { LatLngBounds.Builder builder = LatLngBounds.builder(); builder.include(center); for (LatLng position : positions) { LatLng other = new LatLng(2 * center.latitude - position.latitude, 2 * center.longitude - position.longitude); builder.include(position); builder.include(other); } return builder.build(); }
private static void boundMap(final boolean isListView, final LatLngBounds.Builder builder, final GoogleMap googleMap) { LatLngBounds bounds = builder.build(); googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 50)); float zoom = googleMap.getCameraPosition().zoom; if (isListView) googleMap.moveCamera(CameraUpdateFactory.zoomTo(zoom - 1f)); }
public static void fixZoomForMarkers(GoogleMap googleMap, List<Marker> markers) { if (markers!=null && markers.size() > 0) { LatLngBounds.Builder bc = new LatLngBounds.Builder(); for (Marker marker : markers) { bc.include(marker.getPosition()); } googleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bc.build(), 50),4000,null); } }
public LatLngBounds provideLatLngBoundsForAllPlaces() { LatLngBounds.Builder builder = new LatLngBounds.Builder(); for(Place place : mBaliData.getPlacesList()) { builder.include(new LatLng(place.getLat(), place.getLng())); } return builder.build(); }
LatLngBounds getLatLngBoundsForMarkers() { LatLngBounds.Builder builder = new LatLngBounds.Builder(); builder.include(mOriginMapMarker.getPosition()); builder.include(mDestinationMarker.getPosition()); return builder.build(); }