This example demonstrates ground overlays in OpenMapView, showing how to add images positioned on the map with support for rotation and transparency.
- Ground overlays with two positioning modes
- Position mode: Center point with width/height in meters
- Bounds mode: Stretch image to geographic bounds
- Bearing rotation (0-360 degrees)
- Transparency control (0-100%)
- Clickable ground overlays with listeners
- Z-index ordering for multiple overlays
- Dynamic overlay toggling (show/hide)
- Jetpack Compose UI with Material3
- Open the OpenMapView project in Android Studio
- Select
examples.Example10GroundOverlaysfrom the run configuration dropdown - Click Run
- Deploy to your device or emulator
./gradlew :examples:Example10GroundOverlays:assembleDebug
adb install examples/Example10GroundOverlays/build/outputs/apk/debug/Example10GroundOverlays-debug.apk
adb shell am start -n de.afarber.openmapview.example10groundoverlays/.MainActivityval groundOverlay = GroundOverlay(
image = BitmapDescriptor.BitmapMarker(bitmap),
position = LatLng(51.47, 7.25),
width = 2000f,
bearing = 0f,
transparency = 0f,
clickable = true,
zIndex = 1f
)
mapView.addGroundOverlay(groundOverlay)val groundOverlay = GroundOverlay(
image = BitmapDescriptor.BitmapMarker(bitmap),
bounds = LatLngBounds(
southwest = LatLng(51.46, 7.24),
northeast = LatLng(51.47, 7.26)
),
transparency = 0f,
clickable = true,
zIndex = 2f
)
mapView.addGroundOverlay(groundOverlay)val groundOverlay = mapView.addGroundOverlay(
GroundOverlayOptions()
.image(BitmapDescriptor.BitmapMarker(bitmap))
.position(LatLng(51.465, 7.255), 1500f)
.bearing(45f)
.transparency(0f)
.clickable(true)
.zIndex(3f)
)mapView.setOnGroundOverlayClickListener { groundOverlay ->
Toast.makeText(context, "Clicked: ${groundOverlay.tag}", Toast.LENGTH_SHORT).show()
}val updatedOverlay = currentOverlay.copy(
transparency = 0.5f,
bearing = 90f
)
mapView.removeGroundOverlay(currentOverlay)
mapView.addGroundOverlay(updatedOverlay)- Toggle Position Mode - Shows overlay centered at position with 2000m width
- Toggle Bounds Mode - Shows overlay stretched to geographic bounds
- Toggle Rotated 45deg - Shows overlay rotated 45 degrees clockwise
- Adjust Transparency - Slider changes opacity (0-100%)
- Click Overlays - Tap on overlay to see toast with tag
- Multiple Overlays - Enable multiple overlays to see z-index ordering
- Clear All - FAB button removes all overlays and resets transparency
- Position Mode: Center point + width (and optional height) in meters
- Bounds Mode: Geographic rectangle (LatLngBounds)
- Bearing: Rotation angle in degrees clockwise from north (0-360)
- Anchor: Rotation pivot point, default (0.5, 0.5) = center
- Transparency: 0.0 (opaque) to 1.0 (fully transparent)
- Z-index: Draw order (higher values drawn on top)
- Clickable: Whether overlay responds to touch events
- Campus maps overlaid on street map
- Weather radar imagery
- Historic map comparisons
- Floor plans for indoor navigation
- Custom imagery layers
Default Center: Bochum, Germany (51.4661°N, 7.2491°E) at zoom 13.0
The example uses programmatically generated colored bitmaps with labels to demonstrate the different positioning and rotation modes clearly.
Ground overlays are Google Maps Android API compatible, supporting both positioning modes, rotation, transparency, and click handling.
