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?
Adding click event on your function:addListener(infoWindow, 'domready' () => { const someButton = document. getElementById('btn-click'); if (someButton) { google. maps.
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.
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.
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.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With