showInfoWindow()函数在Google Maps中不起作用

问题描述 投票:-1回答:2

我有一个带有一些标记的google地图,所有标记都有标题和摘录。我将标记存储在HashMap中。我想在单击按钮时使用showInfoWindow()函数显示标题和摘要。这是我的代码:

Marker m = getMarker(location); //this function return marker from HashMap with its location
if(m!=null)
    m.showInfoWindow();

m不为null,但showInfoWindow()不起作用

调试输出:enter image description here

m.getTitle()日志:enter image description here

android google-maps android-maps-v2 android-maps
2个回答
0
投票

将您的代码更改为此

    Marker m = getMarker(location);
if(m!= null){
    m.showInfoWindow();
}

如果标记尚未在地图上渲染,则标记对象将为null,因此请确保在使用标记对象之前检查其是否为null。


0
投票

为了显示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();

© www.soinside.com 2019 - 2024. All rights reserved.