首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android:使用百度地图在折线上添加箭头?

Android:使用百度地图在折线上添加箭头?
EN

Stack Overflow用户
提问于 2020-08-21 19:15:10
回答 1查看 45关注 0票数 0

可以使用百度地图在折线上添加箭头吗?

EN

回答 1

Stack Overflow用户

发布于 2020-08-21 21:01:51

我发现回答我自己和张贴答案,所以它可以帮助其他人。在我的例子中,我需要在折线的末尾添加箭头。

我找不到使用百度SDK实现此功能的任何内置方法,因此我提出了自定义解决方案。这个想法是找到折线的最后两个点之间的方向角,并按该角度旋转箭头位图,并将角度定位在折线的末端。

解决方案。

代码语言:javascript
复制
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)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63521849

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档