可以使用百度地图在折线上添加箭头吗?
发布于 2020-08-21 21:01:51
我发现回答我自己和张贴答案,所以它可以帮助其他人。在我的例子中,我需要在折线的末尾添加箭头。
我找不到使用百度SDK实现此功能的任何内置方法,因此我提出了自定义解决方案。这个想法是找到折线的最后两个点之间的方向角,并按该角度旋转箭头位图,并将角度定位在折线的末端。
解决方案。
val points = polyline.points
val p1 = points[points.size -1]
val p2 = points[points.size -2]
// heading angle between points (+180 is for bringing the value in 0..360 range, as heading's default range is -180..180 degree)
val angle = SphericalUtil.computeHeading(p1,p2)+180 // SphericalUtil link -> https://github.com/googlemaps/android-maps-utils
// rotate the bitmap to fit last two points direction
val rotatedArrowBitmap = arrowBitmap.rotate(angle) // .rotate(value) is a kotlin extention, find ful method below
val markerOptions = MarkerOptions().position(LatLng(p1.latitude, p1.longitude))
.icon(BitmapDescriptorFactory.fromBitmap(bitmap))
.anchor(0.5f, 0.5f) // this will fit marker center with the p1 coordinate
.flat(true) // this will make marker rotate with map
map.addOverlay(markerOptions)https://stackoverflow.com/questions/63521849
复制相似问题