【发布时间】:2017-03-16 15:26:45
【问题描述】:
在 android 地图应用程序中,它显示多条路线的工具提示窗口,就像谷歌地图也显示该窗口一样。我想知道那是自定义标记还是折线上的 infoWindow。
有没有人知道如何通过 android map-v2 集成来实现这一点?
下图显示了我对在 android 中实现的期望。
【问题讨论】:
标签: android google-maps infowindow polyline
在 android 地图应用程序中,它显示多条路线的工具提示窗口,就像谷歌地图也显示该窗口一样。我想知道那是自定义标记还是折线上的 infoWindow。
有没有人知道如何通过 android map-v2 集成来实现这一点?
下图显示了我对在 android 中实现的期望。
【问题讨论】:
标签: android google-maps infowindow polyline
我编写了这个小 Kotlin 扩展函数(只需添加到您的扩展函数或代码中的任何位置)来完成所需的工作:它在折线的中途添加了一个信息窗口。
fun Polyline.addInfoWindow(map: GoogleMap, title: String, message: String) {
val pointsOnLine = this.points.size
val infoLatLng = this.points[(pointsOnLine / 2)]
val invisibleMarker =
BitmapDescriptorFactory.fromBitmap(Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888))
val marker = map.addMarker(
MarkerOptions()
.position(infoLatLng)
.title(title)
.snippet(message)
.alpha(0f)
.icon(invisibleMarker)
.anchor(0f, 0f)
)
marker.showInfoWindow()
}
如下使用:
polyline.addInfoWindow(map, "Title", "Message")
使用示例:
polyline.addInfoWindow(map, route.distanceText, route.durationText)
【讨论】:
如果有人仍在寻找答案,您可以使用maps-utils library 中的气泡图标。它允许您创建自定义标记,看起来就像 infowindows。您可以从here 运行演示,但请确保在运行时导入为项目:File->New->Import Project...
【讨论】:
信息窗口在地图上方的弹出窗口中显示文本或图像。 信息窗口始终固定在标记上。它们的默认行为是在点击标记时显示。
因此,您将不得不使用其他解决方案,而不仅仅是将信息窗口附加到折线。也许你可以在该位置创建一个不可见的标记,折线已被点击,在打开信息窗口的过程中。
【讨论】: