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)); }
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); } } }
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)); } }
private void drawPolyLineAndAnimateCar() { LatLngBounds.Builder builder = new LatLngBounds.Builder(); for (LatLng latLng : polyLineList) { builder.include(latLng);
LatLngBounds area = new LatLngBounds.Builder() .include(mOrigem) .include(mDestino)
@Override public void onMapLoaded() { int count = 0; LatLngBounds.Builder builder = new LatLngBounds.Builder(); for (ExtraMarker extraMarker : viewOption.getMarkers()) { count++;
LatLngBounds.Builder builder = new LatLngBounds.Builder(); for(Marker marker : markers) { builder.include(marker.getPosition());
LatLngBounds.Builder builder = new LatLngBounds.Builder(); for (LatLng latLng : latLngs) { builder.include(latLng); marker.setRotation(getBearing(latLngs.get(0), newPos)); mMap.animateCamera(CameraUpdateFactory.newCameraPosition (new CameraPosition.Builder().target(newPos) .zoom(15.5f).build()));
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)); } });
LatLngBounds getLatLngBoundsForMarkers() { LatLngBounds.Builder builder = new LatLngBounds.Builder(); builder.include(mOriginMapMarker.getPosition()); builder.include(mDestinationMarker.getPosition()); return builder.build(); }
/** * Creates a new builder. */ public Builder builder() { return new Builder(); }
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 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 bounds = new LatLngBounds.Builder() .include(ADELAIDE) .include(BRISBANE)
@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)); }