2323import com .google .android .gms .maps .model .GroundOverlay ;
2424import com .google .android .gms .maps .model .GroundOverlayOptions ;
2525import com .google .android .gms .maps .model .LatLng ;
26+ import com .google .android .gms .maps .model .LatLngBounds ;
2627
2728import android .graphics .Point ;
2829import android .os .Bundle ;
@@ -51,6 +52,10 @@ public class GroundOverlayDemoActivity extends SamplesBaseActivity
5152 private static final LatLng NEWARK = new LatLng (40.714086 , -74.228697 );
5253 private static final LatLng NEAR_NEWARK =
5354 new LatLng (NEWARK .latitude - 0.001 , NEWARK .longitude - 0.025 );
55+ static final LatLngBounds OVERLAY_BOUNDS = new LatLngBounds (
56+ new LatLng (40.7050 , -74.2600 ),
57+ new LatLng (40.7800 , -74.1200 )
58+ );
5459
5560 private final List <BitmapDescriptor > images = new ArrayList <>();
5661
@@ -84,7 +89,7 @@ protected void onCreate(Bundle savedInstanceState) {
8489 setContentView (binding .getRoot ());
8590
8691 binding .transparencySeekBar .setMax (TRANSPARENCY_MAX );
87- binding .transparencySeekBar .setProgress (0 );
92+ binding .transparencySeekBar .setProgress (25 );
8893
8994 // Set up programmatic click listeners for the buttons.
9095 binding .switchImage .setOnClickListener (v -> switchImage ());
@@ -106,10 +111,8 @@ public void onMapReady(GoogleMap map) {
106111 // Register a listener to respond to clicks on GroundOverlays.
107112 map .setOnGroundOverlayClickListener (this );
108113
109- // Move the camera to the Newark area.
110- map .moveCamera (CameraUpdateFactory .newLatLngZoom (NEWARK , 11 ));
111-
112- map .moveCamera (CameraUpdateFactory .scrollBy (100f , 100f ));
114+ // Move the camera to frame the Newark overlays with padding.
115+ map .moveCamera (CameraUpdateFactory .newLatLngBounds (OVERLAY_BOUNDS , 80 ));
113116
114117 map .setOnMapClickListener (ll -> {
115118 Point point = mMap .getProjection ().toScreenLocation (ll );
@@ -141,7 +144,8 @@ public void onMapReady(GoogleMap map) {
141144 // Add a large overlay at Newark on top of the smaller overlay.
142145 groundOverlay = map .addGroundOverlay (new GroundOverlayOptions ()
143146 .image (images .get (currentEntry )).anchor (0 , 1 )
144- .position (NEWARK , 8600f , 6500f ));
147+ .position (NEWARK , 8600f , 6500f )
148+ .transparency ((float ) binding .transparencySeekBar .getProgress () / (float ) TRANSPARENCY_MAX ));
145149 groundOverlay .setTag (images .get (currentEntry ));
146150
147151 binding .transparencySeekBar .setOnSeekBarChangeListener (this );
0 commit comments