Joe Joe - 1 month ago 14
Android Question

How to show both markers on Google Maps?

I have a maps activity that displays an origin and a destination location (Point A and Point B). However, when the origin and destination locations are inputted. Only the Origin is displayed initially. You would have to zoom out to see the destination on the map. How can I show both markers at the same time?

I would like it to fill the entire fragment

Answer

You need to set up a LatLng bounds to fit all of your points (in this case, just two) within the Map's camera. Take this code for example:

final LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(markerA.getPosition()); // this is a LatLng value
builder.include(markerB.getPosition());
mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 100));
Comments