Joe
Joe

Reputation: 5

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

Upvotes: 0

Views: 51

Answers (1)

Jace J McPherson
Jace J McPherson

Reputation: 450

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));

Upvotes: 1

Related Questions