2
votes

MapBox GL JS contains the FitBounds method to centre on some points, and adjust the zoom to fit the bounds in (https://www.mapbox.com/mapbox-gl-js/api/#Map.fitBounds). I can not, however, seem to find any reference to this method in the Android SDK API documentation.

Does anyone know how I can leverage FitBounds(), or an equivalent method of doing so?

1

1 Answers

13
votes

great question. In order to accomplish this you need to create a LatLngBounds and then zoom to that location.

so using the latest SDK version, 4.0.0, you'd achieve this with this code:

LatLngBounds latLngBounds = new LatLngBounds.Builder()
                    .include(first marker position)
                    .include(second marker position)
                    .build();

CameraUpdateFactory.newLatLngBounds(latLngBounds, 10);

You can include as many LatLng as you'd like by including them within your bounding box. Hope this helps!