Android谷歌路线图中的折线上的箭头标记

Ari*_*Ari 6 android google-maps polyline google-maps-android-api-2

如何在Android谷歌地图v2中显示Polyline上的箭头

我已经浏览了几个链接,其中大部分链接到JS https://google-developers.appspot.com/maps/documentation/javascript/examples/overlay-symbol-arrow但我需要在Android而不是JS我可以在Android中使用这些代码

有些人正在使用MapActivity我也按照教程创建了地图活动 https://developers.google.com/maps/documentation/android/v1/hello-mapview但它没有工作我无法生成mapactivity因此我无法'使用locationoverlays

我也有一些评论的帖子,因为它在v3中可用但是现在我的要求是在v2中

这个问题在我知道很多次被问过,但我仍然找不到任何正确的答案

如何在折线上显示箭头以显示我应该去的方向

任何示例或教程都会非常有用.

谢谢

4gu*_*71n 3

Google Maps API v2 演示中中,有一个 MarkerDemoActivity 类,您可以在其中看到如何将自定义图像设置为 GoogleMap。您可以使用标记来显示箭头,如下所示:

\n\n
// First you need rotate the bitmap of the arrowhead somewhere in your code\nMatrix matrix = new Matrix();\nmatrix.postRotate(rotationDegrees);\n// Create the rotated arrowhead bitmap\nBitmap arrowheadBitmap = Bitmap.createBitmap(originalBitmap, 0, 0,\n                      width, height, matrix, true);\n// Now we are gonna to add a marker\nmArrowhead = mMap.addMarker(new MarkerOptions()\n.position(POSITION)\n.icon(arrowheadBitmap));\n
Run Code Online (Sandbox Code Playgroud)\n\n

一些说明: \n当您绘制路线时,或者如果您只是要绘制两个点,则要获取rotationDegrees您可以通过执行以下操作来获取它们:

\n\n
rotationDegrees = Math.toDegrees(Math.atan2(originLat-destinyLat, originLon-destinyLon));\n
Run Code Online (Sandbox Code Playgroud)\n\n

经典的轮换游戏算法 :D

\n\n

确保您的箭头图像朝上。请注意,如果您不想使用图像来显示箭头,而是只想使用折线,则可以通过获取最后一个 LatLng 点(您将在其中显示箭头)并使用来实现这一点翻译来绘制构成箭头的两条线。

\n