Mapbox Android确定包含所有标记的缩放级别

ste*_*706 12 android mapbox

有没有办法确定缩放级别,以便我的所有标记都适合缩放级别?我正在使用mapbox 0.4.0

我认为答案与此类似,但我找不到Android版本

[ https://www.mapbox.com/mapbox.js/example/v1.0.0/markers-only-at-zoom-level/]

Dan*_*gen 14

使用最新的SDK版本,现有的答案不再适用.相反,使用这个:

LatLngBounds latLngBounds = new LatLngBounds.Builder()
  .include(new LatLng(<marker 1 latlng position>)) 
  .include(new LatLng(<marker 2 latlng position>)) 
  .build();

mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(latLngBounds, 50));
Run Code Online (Sandbox Code Playgroud)

感谢友好的Mapbox支持提供这个答案:)


ste*_*706 8

好吧,我已经明白了.我需要创建一个包含所有标记的边界框

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;
}
Run Code Online (Sandbox Code Playgroud)

更新

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));
Run Code Online (Sandbox Code Playgroud)

  • **zoomToBoundingBox()**似乎暂不可用了.有什么选择? (2认同)