Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a button to a custom InfoWindowAdapter view that can register clicks

I'm adding an InfoWindowAdapter with a custom layout to the Android Google Maps API v2 based map fragment. I've put a button in the view I return from getInfoWindow() and while it shows up perfectly fine, when I click on said button the window itself registers a click (blinking with a yellowish tint as usual) while the button does not.

How can I make a button in the info window "clickable"? And, by extension, any view inside an info window?

like image 302
Artemiy Avatar asked Dec 04 '12 16:12

Artemiy


People also ask

How do I add buttons to infoWindow?

Adding click event on your function:addListener(infoWindow, 'domready' () => { const someButton = document. getElementById('btn-click'); if (someButton) { google. maps.

How to Add marker on Google map Android?

For adding a custom marker to Google Maps navigate to the app > res > drawable > Right-Click on it > New > Vector Assets and select the icon which we have to show on your Map. You can change the color according to our requirements. After creating this icon now we will move towards adding this marker to our Map.

What is the use of addMarker() in Maps?

addMarker(markerOptions) method. Markers are designed to be interactive. They receive click events by default, and are often used with event listeners to bring up info windows. Setting a marker's draggable property to true allows the user to change the position of the marker.

How to drag marker on Google Maps in Android?

The most notable point here is the draggable(true) on the MarkerOptions() and the initialization of the startMarker to the map. Setting draggable to true makes the marker draggable and vice versa is true. Now with this, after the marker is shown, you can long-press the marker then drag it to your preferred location.


2 Answers

While you can set an info window to be an arbitrary view using GoogleMap.setInfoWindowAdapter(), the info window that is rendered on the map is not a live view. Instead, it is a snapshot of the view at the time the view was returned by the adapter (see here). So, unfortunately it doesn't behave like a standard view once it is placed on the map.

like image 55
Anthony Avatar answered Oct 21 '22 11:10

Anthony


Instead, listen for marker click events with OnMarkerClickListener and display your own complete view directly. It may be a bit more work to anchor it to the location of the marker, however. Try PopupWindow with showAtLocation(View parent, int gravity, int x, int y)

like image 21
rockgecko Avatar answered Oct 21 '22 12:10

rockgecko