簡體   English   中英

Android谷歌路線圖中的折線上的箭頭標記

[英]Arrow Mark over Polyline in Android Google Route Map

如何在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中

這個問題在我知道很多次被問過,但我仍然找不到任何正確的答案

如何在折線上顯示箭頭以顯示我應該去的方向

任何示例或教程都會非常有用。

謝謝

Google Maps API v2演示中,有一個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º的平移算法繪制出制作箭頭的兩條線。

最近,Google在Google Maps Android API v2中為折線實現了此功能。

他們添加了使用自定義位圖自定義折線的起始和結束大寫的功能。 使用此功能,您可以將箭頭添加到折線。

請參閱“ 形狀指南”中有關線條大寫的信息。 見一個例子中折線和多邊形的教程。

您還可以在此處閱讀相應的博文:

https://maps-apis.googleblog.com/2017/02/styling-and-custom-data-for-polylines.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM