Search in sources :

Example 1 with LatLngBounds

use of com.google.android.libraries.maps.model.LatLngBounds in project android-samples by googlemaps.

the class TagsDemoActivity method onMapReady.

@Override
public void onMapReady(GoogleMap map) {
    mMap = map;
    UiSettings mUiSettings = mMap.getUiSettings();
    // Turn off the map toolbar.
    mUiSettings.setMapToolbarEnabled(false);
    // Disable interaction with the map - other than clicking.
    mUiSettings.setZoomControlsEnabled(false);
    mUiSettings.setScrollGesturesEnabled(false);
    mUiSettings.setZoomGesturesEnabled(false);
    mUiSettings.setTiltGesturesEnabled(false);
    mUiSettings.setRotateGesturesEnabled(false);
    // Add a circle, a ground overlay, a marker, a polygon and a polyline to the map.
    addObjectsToMap();
    // Set listeners for click events.  See the bottom of this class for their behavior.
    mMap.setOnCircleClickListener(this);
    mMap.setOnGroundOverlayClickListener(this);
    mMap.setOnMarkerClickListener(this);
    mMap.setOnPolygonClickListener(this);
    mMap.setOnPolylineClickListener(this);
    // Override the default content description on the view, for accessibility mode.
    // Ideally this string would be localised.
    map.setContentDescription(getString(R.string.tags_demo_map_description));
    // Create bounds that include all locations of the map.
    LatLngBounds bounds = new LatLngBounds.Builder().include(ADELAIDE).include(BRISBANE).include(DARWIN).include(HOBART).include(PERTH).include(SYDNEY).build();
    mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100));
}
Also used : UiSettings(com.google.android.libraries.maps.UiSettings) LatLngBounds(com.google.android.libraries.maps.model.LatLngBounds)

Example 2 with LatLngBounds

use of com.google.android.libraries.maps.model.LatLngBounds in project android-samples by googlemaps.

the class MarkerDemoActivity method onMapReady.

@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));
}
Also used : LatLngBounds(com.google.android.libraries.maps.model.LatLngBounds)

Example 3 with LatLngBounds

use of com.google.android.libraries.maps.model.LatLngBounds in project android-samples by googlemaps.

the class MarkerCloseInfoWindowOnRetapDemoActivity method onMapReady.

@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));
}
Also used : LatLngBounds(com.google.android.libraries.maps.model.LatLngBounds)

Example 4 with LatLngBounds

use of com.google.android.libraries.maps.model.LatLngBounds in project android-maps-utils by googlemaps.

the class CustomMarkerClusteringDemoActivity method onClusterClick.

@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;
}
Also used : ClusterItem(com.google.maps.android.clustering.ClusterItem) LatLngBounds(com.google.android.libraries.maps.model.LatLngBounds)

Example 5 with LatLngBounds

use of com.google.android.libraries.maps.model.LatLngBounds in project android-maps-utils by googlemaps.

the class KmlDemoActivity method moveCameraToKml.

private void moveCameraToKml(KmlLayer kmlLayer) {
    if (mIsRestore)
        return;
    try {
        // 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));
    } catch (Exception e) {
        // may fail depending on the KML being shown
        e.printStackTrace();
    }
}
Also used : LatLngBounds(com.google.android.libraries.maps.model.LatLngBounds) LatLng(com.google.android.libraries.maps.model.LatLng) KmlContainer(com.google.maps.android.data.kml.KmlContainer) KmlPlacemark(com.google.maps.android.data.kml.KmlPlacemark) KmlPolygon(com.google.maps.android.data.kml.KmlPolygon) IOException(java.io.IOException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Aggregations

LatLngBounds (com.google.android.libraries.maps.model.LatLngBounds)8 Nullable (androidx.annotation.Nullable)2 LatLng (com.google.android.libraries.maps.model.LatLng)2 ClusterItem (com.google.maps.android.clustering.ClusterItem)2 UiSettings (com.google.android.libraries.maps.UiSettings)1 KmlContainer (com.google.maps.android.data.kml.KmlContainer)1 KmlPlacemark (com.google.maps.android.data.kml.KmlPlacemark)1 KmlPolygon (com.google.maps.android.data.kml.KmlPolygon)1 IOException (java.io.IOException)1 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)1