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

孤人 提交于 2020-01-01 02:34:06

问题


I am implementing google map V2 in my app.I have added custom info window to marker.There are three images cancel,delete & edit.

onclick, cancel image window hide. delete data delete & on edit dialog open for editing.

My problem is, how perform click operation on on these images?


回答1:


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.




回答2:


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




回答3:


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); 


来源:https://stackoverflow.com/questions/16604020/how-perform-click-operation-on-marker-custom-info-window-on-google-map-v2-in-and

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!