How perform click operation on marker custom info window on google map V2 in android

断了今生、忘了曾经 提交于 2019-12-03 05:43:44
MaciejGórski

There is no direct way to do it, but there seems to be workaround for this (which I haven't tested myself yet). You may see a long description in this answer: https://stackoverflow.com/a/15040761/2183804.

https://developers.google.com/maps/documentation/android/marker

Quoting form the docs

Info window will not respect any of the interactivity typical for a normal view such as touch or gesture events. However you can listen to a generic click event on the whole info window as described below.

Info window is not a live View, rather the view is rendered as an image onto the map. As a result, any listeners you set on the view are disregarded and you cannot distinguish between click events on various parts of the view. You are advised not to place interactive components — such as buttons, checkboxes, or text inputs — within your custom info window.

You can use an OnInfoWindowClickListener to listen to click events on an info window. To set this listener on the map, call GoogleMap.setOnInfoWindowClickListener(OnInfoWindowClickListener). When a user clicks on an info window, onInfoWindowClick(Marker) will be called and the info window will be highlighted in the default highlight color (Holo Blue for devices running Ice Cream Sandwich and newer, orange for earlier versions of Android).

https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/GoogleMap.OnInfoWindowClickListener

Even though this is an old question I still think people are interested in having info windows with buttons, list etc.

You can check the following library - https://github.com/Appolica/InteractiveInfoWindowAndroid

You can basically add your own fragment as an info window using the manager provided by this library. The following is a snippet of how easily the library can be used. Check the link above for more information

 final MapInfoWindowFragment mapInfoWindowFragment =
    (MapInfoWindowFragment) getSupportFragmentManager().findFragmentById(R.id.infoWindowMap);
 final InfoWindow infoWindow = new InfoWindow(marker, markerSpec, fragment);
// Shows the InfoWindow or hides it if it is already opened.
 mapInfoWindowFragment.infoWindowManager().toggle(infoWindow, true); 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!