1

I have a GoogleMap (Lite Mode) object that has been properly initialized. It works properly with a single Marker and focuses on the proper area using CameraUpdate with newLatLngZoom.

However, when it comes to adding two markers, and have the map keep both in view using LatLngBounds, everything goes bonkers. The map is so zoomed out it shows the entire continent, and the two markers are on-top of each other (along with the polyline).

Kindly assume that the data from the pickup and destination is correct

Here's my code:

googleMap.addMarker(new MarkerOptions()
                    .position(pickup)
                    .title(job.getPickupAddress()));

            googleMap.addMarker(new MarkerOptions()
                    .position(destination)
                    .title(job.getDestinationAddress())
                    .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));

            CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(new LatLngBounds.Builder().include(pickup).include(destination).build(), 0);
            googleMap.moveCamera(cameraUpdate);

            String pickupLatLng = job.getPickupLatLong().latitude + "," + job.getPickupLatLong().longitude;
            String destinationLatLng = job.getDestinationLatLong().latitude + "," + job.getDestinationLatLong().longitude;
            plotPolyLines(pickupLatLng, destinationLatLng);

Output:

The output

Asim
  • 6,962
  • 8
  • 38
  • 61

2 Answers2

0

Setting a zoom with latlng bounds is not an effective solution for all use cases.

Might be a related Bug Maps Lite mode with incorrect zoom level first time app starts

Try few solutions / hacks listed here : https://issuetracker.google.com/issues/36218443

Like refreshing the map by destroying and recreating

Also check if by using a single marker with bounds builder if the map sets to the proper zoom level

One last thing make sure that zoom level limits have not been applied.

Gowrav
  • 189
  • 2
  • 17
-1

try changing the line

googleMap.moveCamera(cameraUpdate);

to

googleMap.moveCamera( CameraUpdateFactory.newLatLngZoom(new LatLng(xxxx,xxxx) , 14.0f) );

as suggested in How do I set default location and Zoom level for google map api v2? or use

 map.animateCamera(CameraUpdateFactory.zoomTo(15),  2000, null);

That should move the camera closer to your marker.

  • 4
    But that wouldn't center the camera over the two markers. The whole point of using bounds is so both markers can be in view. – Asim May 25 '17 at 12:08