【问题标题】:showInfoWindow() function doesn't work in Google MapsshowInfoWindow() 函数在 Google 地图中不起作用
【发布时间】:2020-04-30 22:38:31
【问题描述】:

我有一个带有一些标记的谷歌地图,它们都有标题和 sn-p。我将标记存储在 HashMap 中。我想在单击按钮时使用 showInfoWindow() 函数显示标题和 sn-p。 这是我的代码:

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

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

调试输出:

m.getTitle() 日志:

【问题讨论】:

    标签: android google-maps android-maps-v2 android-maps


    【解决方案1】:

    把你的代码改成这个

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

    如果标记尚未在地图上呈现,则标记对象将为空,因此请务必在使用前检查标记对象是否为空。

    【讨论】:

    • 能分享一下调试输出吗
    【解决方案2】:

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

    【讨论】:

    • 它有标题。查看调试输出
    • 可以通过调用marker.getTitle()来记录marker的标题吗?
    猜你喜欢
    • 1970-01-01
    • 2013-11-18
    • 2016-05-11
    • 1970-01-01
    • 2016-02-01
    • 2019-04-02
    • 1970-01-01
    • 1970-01-01
    • 2020-01-30
    相关资源
    最近更新 更多