My polyline Going out of focus. I'm using map.moveCamera(CameraUpdateFactory.newLatLngZoom(route.startLocation, 10));
but this is not a solution. How to do slove this issue
To solve your problem, lets first understand how the google map camera works. When you do:
map.moveCamera(CameraUpdateFactory.newLatLngZoom(route.startLocation, 10));
The camera focuses the startlocation in the middle with 10 as the zoom level. What we need is to focus the route. For this we need to use the latLng bounds. Once we create a bound with two or more latLngs, we can set it to the camera of the map. This way your route is visible to your users.
Create a bound with all the start and end markers on your route:
LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(startMarker);
builder.include(endMarker);
LatLngBounds bounds = builder.build();
Then obtain a movement description object by using the factory: CameraUpdateFactory
:
int padding = 0; // padding around start and end marker
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
googleMap.animateCamera(cu);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With