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

14
2个回答

15

最新的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));

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


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;
}

更新

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));

3
"zoomToBoundingBox()" 看起来已经不再可用了,有什么可替代的方法吗?" - Tobias
1
@cuddlecheek 像素 - stephen1706

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接