如何在Android Google map v2中显示折线上的箭头
我已经通过了几个链接,其中大多数给出了JS https://google-developers.appspot.com/maps/documentation/javascript/examples/overlay-symbol-arrow的链接,但我需要在安卓而不是JS,我不能使用这些代码在安卓
有些人正在使用MapActivity我按照教程创建地图活动也是https://developers.google.com/maps/documentation/android/v1/hello-mapview,但它不起作用我无法生成地图活动,因此我无法使用位置叠加
我也有一些帖子评论,因为它在v3中可用,但现在我的需求是在v2中
这个问题在这里已经被问了很多次了,我知道,但我仍然找不到任何合适的答案
如何在折线上显示箭头以指示我应该去的方向
任何示例或教程都会非常有帮助。
谢谢
发布于 2013-10-06 10:28:18
在Google Maps API v2 Demo中有一个MarkerDemoActivity类,您可以在其中看到如何将自定义图像设置为GoogleMap。您可以使用标记来显示箭头,如下所示:
// First you need rotate the bitmap of the arrowhead somewhere in your code
Matrix matrix = new Matrix();
matrix.postRotate(rotationDegrees);
// Create the rotated arrowhead bitmap
Bitmap arrowheadBitmap = Bitmap.createBitmap(originalBitmap, 0, 0,
width, height, matrix, true);
// Now we are gonna to add a marker
mArrowhead = mMap.addMarker(new MarkerOptions()
.position(POSITION)
.icon(arrowheadBitmap));一些说明:当你在绘制一条路线时,或者如果你只是有两个点要画,要获得rotationDegrees,你可以这样做:
rotationDegrees = Math.toDegrees(Math.atan2(originLat-destinyLat, originLon-destinyLon));经典的旋转游戏算法:D
确保您的箭头图像指向上方。请注意,如果您不想使用图像来显示箭头,而是只想使用折线,则可以通过取最后一个LatLng点(您将在此处显示箭头)并使用45º的translation算法来绘制构成箭头的两条线来实现此目的。
发布于 2017-03-10 21:13:30
最近,谷歌在Google Maps Android API v2中为折线实现了此功能。
他们添加了使用自定义位图自定义多段线的起点和终点封口的功能。使用此功能,您将能够向多段线添加箭头。
请参阅Shapes Guide中有关线条大写字母的信息。请参见多段线和多边形教程中的example。
你也可以在这里阅读相应的博客文章:
https://maps-apis.googleblog.com/2017/02/styling-and-custom-data-for-polylines.html
https://stackoverflow.com/questions/18274920
复制相似问题