我有一个带有一些标记的google地图,所有标记都有标题和摘录。我将标记存储在HashMap中。我想在单击按钮时使用showInfoWindow()函数显示标题和摘要。这是我的代码:
Marker m = getMarker(location); //this function return marker from HashMap with its location
if(m!=null)
m.showInfoWindow();
m不为null,但showInfoWindow()不起作用
将您的代码更改为此
Marker m = getMarker(location);
if(m!= null){
m.showInfoWindow();
}
如果标记尚未在地图上渲染,则标记对象将为null,因此请确保在使用标记对象之前检查其是否为null。
为了显示infoWindow
,您的标记必须带有标题。
MarkerOptions marker = new MarkerOptions().position(location)
.icon(BitmapDescriptorFactory.fromBitmap(aBitmapFile))
.title("The Title"); //here is title
mapPoint p = new mapPoint(lat, lng);
googleMap.addMarker(marker);
然后您可以在标记上呼叫:.showInfoWindow();
。