【发布时间】:2019-04-17 03:30:51
【问题描述】:
我正在使用折线在 Android 中的 Google 地图上绘制路线。我希望在我的第一条折线上有一个起始上限,向用户显示路线开始的位置。
但是,当我显示的路线必须用多条折线显示并且最后一条折线在第一条折线开始的位置附近结束时,我有时会看到起始端显示在最后一条折线后面。
这种情况并非每次都会发生。我想确保起始上限始终显示在任何和所有折线上方。如何确保帽子显示在所有折线之上?
这是我用来在地图上绘制路线的方法:
private fun addRoute(context: Context, map: GoogleMap, mapData: MapData, color: Int) {
mapData.routeSegments.forEachIndexed { index, segment ->
val polylineOptions = PolylineOptions()
segment.points.forEach { point ->
polylineOptions.add(LatLng(point.latitude, point.longitude))
}
val polyline = map.addPolyline(polylineOptions)
polyline.isClickable = false
polyline.color = color
polyline.width = POLYLINE_WIDTH
if (index == 0) {
val bitmap = DrawableUtil.getBitmapFromVectorDrawable(context, R.drawable.star_red_28px)
polyline.startCap = CustomCap(BitmapDescriptorFactory.fromBitmap(bitmap))
}
}
}
预期:
实际:
【问题讨论】:
标签: java android google-maps kotlin