private void moveCameraToKml(KmlLayer kmlLayer) { //Retrieve the first container in the KML layer KmlContainer container = kmlLayer.getContainers().iterator().next(); //Retrieve a nested container within the first container container = container.getContainers().iterator().next(); //Retrieve the first placemark in the nested container KmlPlacemark placemark = container.getPlacemarks().iterator().next(); //Retrieve a polygon object in a placemark KmlPolygon polygon = (KmlPolygon) placemark.getGeometry(); //Create LatLngBounds of the outer coordinates of the polygon LatLngBounds.Builder builder = new LatLngBounds.Builder(); for (LatLng latLng : polygon.getOuterBoundaryCoordinates()) { builder.include(latLng); } int width = getResources().getDisplayMetrics().widthPixels; int height = getResources().getDisplayMetrics().heightPixels; getMap().moveCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), width, height, 1)); }
@Override public void getMapScreenBounds(OnMapBoundsCallback callback) { final Projection projection = googleMap.getProjection(); int hOffset = getResources().getDimensionPixelOffset(R.dimen.map_horizontal_padding); int vOffset = getResources().getDimensionPixelOffset(R.dimen.map_vertical_padding); LatLngBounds.Builder builder = LatLngBounds.builder(); builder.include(projection.fromScreenLocation(new Point(hOffset, vOffset))); // top-left builder.include(projection.fromScreenLocation( new Point(getView().getWidth() - hOffset, vOffset))); // top-right builder.include(projection.fromScreenLocation( new Point(hOffset, getView().getHeight() - vOffset))); // bottom-left builder.include(projection.fromScreenLocation(new Point(getView().getWidth() - hOffset, getView().getHeight() - vOffset))); // bottom-right callback.onMapBoundsReady(builder.build()); }
@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; }
.include(firstLatLng) .include(secondLatLng) .build(); CameraUpdate bUpdate = CameraUpdateFactory.newLatLngBounds(llBounds, 0); mMap.animateCamera(bUpdate);
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))); } } });
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 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))); } }
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 LatLngBounds provideLatLngBoundsForAllPlaces() { LatLngBounds.Builder builder = new LatLngBounds.Builder(); for(Place place : mBaliData.getPlacesList()) { builder.include(new LatLng(place.getLat(), place.getLng())); } 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)); }
private LatLng calculateClusterPosition() { LatLngBounds.Builder builder = LatLngBounds.builder(); for (DelegatingMarker m : markers) { builder.include(m.getPosition()); } return builder.build().getCenter(); }
LatLngBounds getLatLngBoundsForMarkers() { LatLngBounds.Builder builder = new LatLngBounds.Builder(); builder.include(mOriginMapMarker.getPosition()); builder.include(mDestinationMarker.getPosition()); return builder.build(); }
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(); }
.include(PERTH) .include(SYDNEY) .build(); mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100));
@Override public void onMapReady(GoogleMap map) { mMap = map; // Hide the zoom controls as the button panel will cover it. mMap.getUiSettings().setZoomControlsEnabled(false); // Add lots of markers to the map. addMarkersToMap(); // Setting an info window adapter allows us to change the both the contents and look of the // info window. mMap.setInfoWindowAdapter(new CustomInfoWindowAdapter()); // Set listeners for marker events. See the bottom of this class for their behavior. mMap.setOnMarkerClickListener(this); mMap.setOnInfoWindowClickListener(this); mMap.setOnMarkerDragListener(this); mMap.setOnInfoWindowCloseListener(this); mMap.setOnInfoWindowLongClickListener(this); // Override the default content description on the view, for accessibility mode. // Ideally this string would be localised. mMap.setContentDescription("Map with lots of markers."); LatLngBounds bounds = new LatLngBounds.Builder() .include(PERTH) .include(SYDNEY) .include(ADELAIDE) .include(BRISBANE) .include(MELBOURNE) .include(DARWIN) .build(); mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 50)); }
@Override public void onMapReady(GoogleMap map) { mMap = map; // Hide the zoom controls. mMap.getUiSettings().setZoomControlsEnabled(false); // Add lots of markers to the map. addMarkersToMap(); // Set listener for marker click event. See the bottom of this class for its behavior. mMap.setOnMarkerClickListener(this); // Set listener for map click event. See the bottom of this class for its behavior. mMap.setOnMapClickListener(this); // Override the default content description on the view, for accessibility mode. // Ideally this string would be localized. map.setContentDescription("Demo showing how to close the info window when the currently" + " selected marker is re-tapped."); LatLngBounds bounds = new LatLngBounds.Builder() .include(PERTH) .include(SYDNEY) .include(ADELAIDE) .include(BRISBANE) .include(MELBOURNE) .build(); mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 50)); }
/** * Move the camera to show all of Australia. * Construct a {@link com.google.android.gms.maps.model.LatLngBounds} from markers positions, * then move the camera. */ public void showAustralia(View v) { // Wait until map is ready if (mMap == null) { return; } // Create bounds that include all locations of the map LatLngBounds.Builder boundsBuilder = LatLngBounds.builder() .include(PERTH) .include(ADELAIDE) .include(MELBOURNE) .include(SYDNEY) .include(DARWIN) .include(BRISBANE); // Move camera to show all markers and locations mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(boundsBuilder.build(), 20)); }
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); } } }
@Override public void run() { CameraUpdate allTheThings= CameraUpdateFactory.newLatLngBounds(builder.build(), 32); map.moveCamera(allTheThings); } });