简体   繁体   中英

How to use FitBounds on MapBox Android SDK?

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?

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM