简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM