zoom over specific route google map

前端 未结 9 1079
感动是毒
感动是毒 2021-02-05 11:23

I have a list of random latitude and longitude points and I am drawing a route between them. My question is how to bound this route within google map I made below utili

9条回答
  •  被撕碎了的回忆
    2021-02-05 12:00

    You need to include all the points that form the polyline into your mapBounds object.

    Also, you are updating the camera using animateCamera and then you are moving it using moveCamera. This second camera update overrides the first one. Just remove the line

    googleMap.moveCamera(CameraUpdateFactory.zoomOut());
    

    This line is also innecesary (you don't need to move and animate the camera, just one of them):

    googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(mapBounds.build(), 10));
    

    If you need to zoom out a bit your map you can play with the padding parameter of the CameraUpdateFactory.newLatLngBounds method.

提交回复
热议问题