我有一个带有一些标记的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。