I have a map in which I show a series of points linked by Polylines, the map is LiteMode, but under certain circumstances when creating a LatLngBounds with those points and updating the camera some points are left out of the map.
LatLngBounds.Builder builder = new LatLngBounds.Builder();
for (LatLng latLng : listPoints) {
builder.include(latLng);
}
LatLngBounds bounds = builder.build();
int padding = 0; //offset from edges of the map in pixels
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
map.moveCamera(cu);
How can I solve that?
Through the polylines we can see that they are out of sight even by changing the pading: And so it is seen if I remove the LiteMode:
The Maps SDK for Android can serve a bitmap image of a map, offering limited interactivity to the user. This is called a lite mode map.
An immutable class representing a latitude/longitude aligned rectangle.
I solved the problem!
According to Google Maps Lite Mode documentation says:
Camera position, zoom, and animation
Supported? Partly
You can set the camera target and zoom, but not the tilt or bearing. Zoom level is rounded to the nearest integer in lite mode. Calling GoogleMap.moveCamera() will give you another static map image. For more information on setting and manipulating the camera, see Changing the View.
My solution was to get Visible Region from the map and compare to see if any of the points on my list were outside that region, if so, I applied ZoomOut to zoom out the camera enough so that all my points were in the visible region.
for (LatLng latLng : listPoints) {
if (!(map.getProjection().getVisibleRegion().latLngBounds.contains(latLng))) {
map.moveCamera(CameraUpdateFactory.zoomOut());
break;
}
}
Apparently the problem as I understand it is that if the zoom level is for example 7.4 to correctly display all the points on the map by rounding it to the nearest integer: 7, a valuable .4 margin is lost than when the LiteMode This disabled is rounded to 8.
I do not know if it is the most optimal option but the problem has been solved. Any opinion is welcome! :)
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