【发布时间】:2013-11-17 12:44:15
【问题描述】:
我可以在谷歌地图中只显示信息窗口吗?我正在使用 Google Map 的 V2 api 开发一个 Android 应用程序。我想在信息窗口中显示路线信息,但不想显示标记图标。那么信息窗口可以与标记分开吗?如果是这样,我怎样才能在隐藏标记的同时只显示信息窗口。
谢谢
【问题讨论】:
标签: android google-maps-android-api-2
我可以在谷歌地图中只显示信息窗口吗?我正在使用 Google Map 的 V2 api 开发一个 Android 应用程序。我想在信息窗口中显示路线信息,但不想显示标记图标。那么信息窗口可以与标记分开吗?如果是这样,我怎样才能在隐藏标记的同时只显示信息窗口。
谢谢
【问题讨论】:
标签: android google-maps-android-api-2
您可以将标记的不透明度指定为 0。
我结合@Xingang 的答案来获得更好的结果。
marker.setAlpha(0.0f);
marker.setInfoWindowAnchor(.5f,1.0f);
【讨论】:
map.setOnMapClickListener(ignored -> marker.showInfoWindow())(这里使用retrolambda简化了监听器匿名内部类)。
哇,这样做会很有趣。我不知道你是否可以在没有标记的情况下做到这一点。
因为谷歌的文档是这样说的:
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。
链接:
small tutorial on android custom infowindow
希望对您有所帮助。
如果这对你有用,请告诉我,渴望知道你的回应。
谢谢。
【讨论】:
我懒得用透明图片作为图标,我想在某些情况下显示图标并在其他情况下隐藏它。所以我将信息窗口的位置向下移动以隐藏图标。
marker.setInfoWindowAnchor(.5f, 1.0f);
顺便说一句,marker.setVisible(false) 不起作用,因为它也隐藏了信息窗口。
【讨论】: