Hide markers info window in android google maps API v2

北慕城南 提交于 2020-07-04 10:16:47

问题


Currently I was able to view all my markers in Google maps using Android Google maps API v2.

Adding my marker in map:

mapView.addMarker
     (new MarkerOptions()
      .position(aUsersLocation).
      icon(BitmapDescriptorFactory.fromBitmap(aUserImage))
      .snippet(My_VALUE_1)
      .title(My_VALUE_2)
     .hideInfoWindow();

I have several markers and assigned few values (My_VALUE_1 and My_VALUE_2) to each marker's snippet and title. When user clicks a marker, I need these unique value and I will receive these values in onMarkerClick listener as:

        @Override
        public boolean onMarkerClick(Marker theMarker) 
        {
            String aValue1 = theMarker.getSnippet();
            String aValue2 = theMarker.getTitle();
            theMarker.getPosition().latitude...
           ...
            return false;
        }

My question is: as I am adding the snippet and title values to the marker, when user clicks the marker, infoWindow is displayed.

I need to hide the marker's infoWindow. I tried with hideInfoWindow, but it seems to be not working.

Any suggestions please.

Thank You.


回答1:


return true;

from onMarkerClick to disable default behavior of showing info window and centering on the marker.




回答2:


If you use clusters, write so:

private var clusterManager: ClusterManager<SomeClusterItem>? = null

override fun onMapReady(googleMap: GoogleMap) {
    this.googleMap = googleMap

    clusterManager = ClusterManager(context!!, googleMap)
    ... // Other clusterManager and clusterRenderer initializations.

    clusterManager!!.setOnClusterItemClickListener { item ->
        // selectMarker(item)
        true // false, if you want to show InfoWindow.
    }
}


来源:https://stackoverflow.com/questions/17177207/hide-markers-info-window-in-android-google-maps-api-v2

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