How to add button to Google API v2 Google Maps


I am working on google maps android apps and i am having problems with map markers.

This question may have a trivial solution, but after searching, I found links on how to add a marker using a button. What I want is different: I want a marker that has a button in the corresponding dialog.

Has anyone done something like this?

+3


source to share


2 answers


While you can create InfoWindowAdapter

and attach it to GoogleMap

through setInfoWindowAdapter()

to customize the content of the information window containing Button

, Button

will not be available for clicks. View

that you return from getInfoContents()

to InfoWindowAdapter

is not displayed. Rather, it is converted to Bitmap

, and that image is what is displayed.



However, you can find out when the user clicks on the information window through OnInfoWindowClickListener

registered through setOnInfoWindowClickListener()

on your GoogleMap

.

+6


source


@CommonsWare's notes about converting InfoContent

to Bitmap

are correct. Therefore, you cannot use InfoWindows. Try using an event GoogleMap.OnMarkerClickListener

instead to render your own view on top of the MapView. GoogleMap.OnMarkerClickListener

will help you use clicked marker as parameter.

If you want to display the view at the correct position, you need to calculate the position of the screen. Use Projection method toScreenLocation(LatLng location)

returning Point

to convert LatLng to screen position wrt GoogleMap.



See Projection for details .

+2


source







All Articles