Reputation: 1769
I am working on an android Google Maps app, and am having trouble with map markers.
This question might have a trivial solution but after searching, I have only found links on how to add a marker with a button. What I want is different: I want a marker whose respective dialog box has a button.
Has anyone done anything similar to this?
Upvotes: 4
Views: 4410
Reputation: 5517
The remarks from @CommonsWare about the InfoContent
getting converted to a Bitmap
are true. Therefor you cannot use the InfoWindows. Try to use the GoogleMap.OnMarkerClickListener
event instead to display your own view on top of the MapView. The GoogleMap.OnMarkerClickListener
will help you to use clicked marker as a parameter.
If you want to display the view on the correct position, you have to calculate the screen-position. Use the Projection's toScreenLocation(LatLng location)
method returning Point
to convert the LatLng to the screen position w.r.t GoogleMap.
See Projection for more information.
Upvotes: 2
Reputation: 1007554
While you can create an InfoWindowAdapter
, and attach it to your GoogleMap
via setInfoWindowAdapter()
, to tailor the contents of an info window to contain a Button
, the Button
will not be clickable. The View
you return from getInfoContents()
in InfoWindowAdapter
is not displayed. Rather, it is converted into a Bitmap
, and that image is what is displayed.
However, you can find out when the user taps on the info window via an OnInfoWindowClickListener
registered via setOnInfoWindowClickListener()
on your GoogleMap
.
Upvotes: 7