Mapbox Android确定包含所有标记的缩放级别
问题描述:
是否可以确定缩放级别,以便我所有的标记都适合缩放级别?我正在使用mapbox 0.4.0
Is there a way to determine a zoom level so that all of my markers can fit in the zoom level? i am using mapbox 0.4.0
我认为答案与此类似,但找不到Android版本
I think the answer is similar to this, but I can't find the android version
[ https://www.mapbox.com/mapbox.js/example/v1.0.0/markers-only-at-zoom-level/]
答
好的,我知道了.我需要创建一个包含所有标记的边界框
okay I've figure it out. I need to create a bounding box containing all the markers
final BoundingBox zoomLevel = findZoomLevel(hotelLocation,poiLocations);
mv.zoomToBoundingBox(zoomLevel,true,true);
.....
private BoundingBox findZoomLevel(LatLng hotelLocation, LatLng[] poiLocations) {
double bottomPadding = 0.002;
double topPadding = 0.005;
BoundingBox box = new BoundingBox(findTopMost(hotelLocation,poiLocations).getLatitude() + topPadding,
findRightMost(hotelLocation,poiLocations).getLongitude(),
findBottomMost(hotelLocation,poiLocations).getLatitude() - bottomPadding,
findLeftMost(hotelLocation,poiLocations).getLongitude());
return box;
}
更新
LatLngBounds latLngBounds = new LatLngBounds.Builder()
.include(new LatLng(lat1,lng1))
.include(new LatLng(lat2,lng2))
.build();
mapboxMap.moveCamera(
CameraUpdateFactory.newLatLngBounds(LatLngBounds bounds,
int paddingLeft,
int paddingTop,
int paddingRight,
int paddingBottom));