【问题标题】:how to show an info window without showing the icon of a marker in google map如何在不显示谷歌地图中标记图标的情况下显示信息窗口
【发布时间】:2013-11-17 12:44:15
【问题描述】:

我可以在谷歌地图中只显示信息窗口吗?我正在使用 Google Map 的 V2 api 开发一个 Android 应用程序。我想在信息窗口中显示路线信息,但不想显示标记图标。那么信息窗口可以与标记分开吗?如果是这样,我怎样才能在隐藏标记的同时只显示信息窗口。

谢谢

【问题讨论】:

    标签: android google-maps-android-api-2


    【解决方案1】:

    您可以将标记的不透明度指定为 0。

    我结合@Xingang 的答案来获得更好的结果。

    marker.setAlpha(0.0f);
    marker.setInfoWindowAnchor(.5f,1.0f);
    

    【讨论】:

    • 很棒的提示!虽然我注意到点击地图上的任意位置后信息窗口消失了,我想出了以下插件来保持它:map.setOnMapClickListener(ignored -> marker.showInfoWindow())(这里使用retrolambda简化了监听器匿名内部类)。
    【解决方案2】:

    哇,这样做会很有趣。我不知道你是否可以在没有标记的情况下做到这一点。

    因为谷歌的文档是这样说的:

    Google Maps for Android V2

        An info window allows you to display information to the user when they tap on a marker
     on a map. By default, an info window is displayed when a user taps on a marker if the
     marker has a title set. Only one info window is displayed at a time. If a user clicks on
     another marker, the current window will be hidden and the new info window will be
     displayed. You can show an info window programmatically by calling showInfoWindow() on the
     target marker. An info window can be hidden by calling hideInfoWindow().
    

    但你可以欺骗一件事,只需尝试使用代码将透明标记图像作为资源

    Marker marker = myMap.addMarker(new MarkerOptions()
                         .position(latLng)
                         .title("Title")
                         .snippet("Snippet")
                         .icon(BitmapDescriptorFactory
                         .fromResource(R.drawable.marker))); // transparent image
    
    marker.showInfoWindow();
    

    R.drawable.marker 上使用您的自己的标记,这将是一个透明的。

    编辑:

    除此之外,我确定如果您想在该信息窗口中显示您的路线信息,您应该使用 自定义信息窗口

    您可以使用XML 或仅使用图像来创建自己的自定义infowindow

    链接:

    custom infowindow

    small tutorial on android custom infowindow

    希望对您有所帮助。

    如果这对你有用,请告诉我,渴望知道你的回应。

    谢谢。

    【讨论】:

    • 这很有趣。一定会试试的!感谢您的建议@Ankxx13。作为旁注,我想知道这是否只能通过信息窗口来实现。我的目的是显示有关路线段的信息,您是否看到 Android 中的任何其他 UI 组件可能可用于此场景?
    • 感谢您的回答,真的很有帮助
    【解决方案3】:

    我懒得用透明图片作为图标,我想在某些情况下显示图标并在其他情况下隐藏它。所以我将信息窗口的位置向下移动以隐藏图标。

    marker.setInfoWindowAnchor(.5f, 1.0f);
    

    顺便说一句,marker.setVisible(false) 不起作用,因为它也隐藏了信息窗口。

    【讨论】:

      猜你喜欢
      • 2013-09-13
      • 1970-01-01
      • 2013-03-26
      • 2014-10-15
      • 2014-07-12
      • 2016-05-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多