Joolz Zenda
Joolz Zenda

Reputation: 47

Overlay an image on google maps android api v2

I am trying to use GroundOverlay to add an image to my map. I'm working with the example from

https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/model/GroundOverlay

which is given like this

GoogleMap map = ...; // get a map.
BitmapDescriptor image = ...; // get an image.
LatLngBounds bounds = ...; // get a bounds
// Adds a ground overlay with 50% transparency.
GroundOverlay groundOverlay = map.addGroundOverlay(new GroundOverlayOptions()
 .image(image)
 .positionFromBounds(bounds)
 .transparency(0.5));

However I don't know how to get the image as a bitmapdescriptor. I also don't know how to input the latlngBounds. Any help would be appreciated, the only tutorials I can find online are for API v.1 and no longer seem to work.

Upvotes: 2

Views: 8959

Answers (1)

MaciejGórski
MaciejGórski

Reputation: 22232

BitmapDescriptorFactory can create BitmapDescriptors for you from various objects, e.g.

BitmapDescriptor image = BitmapDescriptorFactory.fromResource(R.drawable.myimage);

You don't need to use positionFromBounds if you don't want to. There are alternative ways to create from central LatLng and width in meters: GroundOverlayOptions.position.

Upvotes: 5

Related Questions