繁体   English   中英

Android:使用百度map在折线上添加箭头?

[英]Android: Add arrow heads on poly line using Baidu map?

是否可以使用百度 map 在折线上添加箭头?

我找到了自己的答案并发布了答案,以便对其他人有所帮助。 在我的例子中,我需要在多边形线的末尾添加箭头。

我在百度 SDK 上找不到任何内置的方法来做到这一点,所以我想出了自定义解决方案。 这个想法是找到多段线最后两点之间的航向角,然后将箭头 bitmap 旋转该角度,然后 position 旋转多段线末端的角度。

解决方案。

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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM