Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LatLngBounds or CameraUpdate not show all points in Maps Lite Mode

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:1 And so it is seen if I remove the LiteMode: 2]

like image 557
Latm Avatar asked Dec 24 '16 23:12

Latm


People also ask

What is Lite mode in Google Maps?

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.

What is Google Maps Latlngbounds?

An immutable class representing a latitude/longitude aligned rectangle.


1 Answers

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! :)

like image 91
Latm Avatar answered Sep 29 '22 09:09

Latm