Search in sources :

Example 6 with LatLngBounds

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

the class ZoomClusteringDemoActivity method onClusterClick.

@Override
public boolean onClusterClick(Cluster<MyItem> cluster) {
    // Show a toast with some info when the cluster is clicked.
    String title = cluster.getItems().iterator().next().getTitle();
    Toast.makeText(this, cluster.getSize() + " (including " + title + ")", 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());
    }
    // Animate camera to the bounds
    try {
        getMap().animateCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 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 7 with LatLngBounds

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

the class AutocompleteTestActivity method getBounds.

@Nullable
private RectangularBounds getBounds(int resIdSouthWest, int resIdNorthEast) {
    String southWest = ((TextView) findViewById(resIdSouthWest)).getText().toString();
    String northEast = ((TextView) findViewById(resIdNorthEast)).getText().toString();
    if (TextUtils.isEmpty(southWest) && TextUtils.isEmpty(northEast)) {
        return null;
    }
    LatLngBounds bounds = StringUtil.convertToLatLngBounds(southWest, northEast);
    if (bounds == null) {
        showErrorAlert(R.string.error_alert_message_invalid_bounds);
        return null;
    }
    return RectangularBounds.newInstance(bounds);
}
Also used : LatLngBounds(com.google.android.libraries.maps.model.LatLngBounds) Nullable(androidx.annotation.Nullable)

Example 8 with LatLngBounds

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

the class StringUtil method convertToLatLngBounds.

@Nullable
static LatLngBounds convertToLatLngBounds(@Nullable String southWest, @Nullable String northEast) {
    LatLng soundWestLatLng = convertToLatLng(southWest);
    LatLng northEastLatLng = convertToLatLng(northEast);
    if (soundWestLatLng == null || northEast == null) {
        return null;
    }
    return new LatLngBounds(soundWestLatLng, northEastLatLng);
}
Also used : LatLngBounds(com.google.android.libraries.maps.model.LatLngBounds) LatLng(com.google.android.libraries.maps.model.LatLng) Nullable(androidx.annotation.Nullable)

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