我的折线不清晰。我正在使用map.moveCamera(CameraUpdateFactory.newLatLngZoom(route.startLocation, 10));
但这不是解决方案。如何解决这个问题
最佳答案
为了解决您的问题,让我们先了解一下Google Map Camera的工作原理。当您这样做时:
map.moveCamera(CameraUpdateFactory.newLatLngZoom(route.startLocation, 10));
相机将起始位置聚焦在中间,缩放级别为10。我们需要的是集中路线。为此,我们需要使用latLng边界。创建具有两个或更多latLng的边界后,可以将其设置为 map 的摄像机。这样,您的用户就可以看到您的路线。
使用路线上的所有开始和结束标记创建边界:
LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(startMarker);
builder.include(endMarker);
LatLngBounds bounds = builder.build();
然后通过使用工厂获取运动描述对象:
CameraUpdateFactory
:int padding = 0; // padding around start and end marker
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
googleMap.animateCamera(cu);