我想将计算出的导航路线居中到地图视图的给定布局中。我尝试用边界来做到这一点,但是路线并不居中。到目前为止,还有其他方法吗?

private fun animateCamera(){
        val bounds = LatLngBounds.Builder()
                .include(LatLng(originPoint.latitude(), originPoint.longitude())) // Northeast
                .include(LatLng(destinationPoint.latitude(), destinationPoint.longitude())) // Southwest
                .build()
        map.easeCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100), 5000)
}

最佳答案

我认为这里最好的选择是MapboxMap#getCameraForLatLngBounds(LatLngBounds latLngBounds, int[] padding)。此方法知道地图的当前状态,从而提供更准确的CameraPosition。所以用你的代码:

private fun animateCamera() {
  val bounds = LatLngBounds.Builder()
            .include(LatLng(originPoint.latitude(), originPoint.longitude())) // Northeast
            .include(LatLng(destinationPoint.latitude(), destinationPoint.longitude())) // Southwest
            .build()

  // zero padding
  val cameraPosition = map.getCameraForLatLngBounds(bounds, intArrayOf(0, 0, 0, 0))
  mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 5000)
}


希望这可以帮助!感谢您签出Mapbox🚀

关于android - Mapbox Android:缩放特定路线,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53604132/

10-13 22:56