Arrow marks polyline in google google map route

how to show arrowheads over polyline in android google map v2

I went through a couple of links, most of them give a link to JS https://google-developers.appspot.com/maps/documentation/javascript/examples/overlay-symbol-arrow , but I need not JS in Android, and I can’t use these codes in android

Some use MapActivity. I also followed the map tutorial. https://developers.google.com/maps/documentation/android/v1/hello-mapview , but it didn’t work, I can’t create a mapactivity property, and therefore I couldn’t use locationoverlays

I also have comments on comments since they are available in version 3, but now my requirement is in v2

This question has been asked many times here, I know, but still I could not find the correct answer.

how can i show the arrow above the polyline to show the direction i should go

any examples or guides will be very helpful.

thanks

+6
source share
2 answers

In the Google Maps API v2 Demo, there is the MarkerDemoActivity class in which you can see how the custom image is installed in GoogleMap. You can use the marker to show the arrow as follows:

// 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)); 

Some clarification: When you draw a route, or if you just got two points to get rotationDegrees , you can get them by doing the following:

 rotationDegrees = Math.toDegrees(Math.atan2(originLat-destinyLat, originLon-destinyLon)); 

Classic rotation game algorithm: D

Make sure the arrow is pointing up. Please note: if you do not want to use the image to display the arrow, and instead you want to use only polylines, you can achieve this by taking the last LatLng point (where you are going to display the arrow) and use the 45º translation algorithm to draw two lines that create the arrow.

+3
source

Google recently applied this feature to polylines in the Google Maps Android API v2.

They added the ability to customize the start and end covers of polylines with a custom raster image. Using this, you can add arrows to your polylines.

See line cap information in the Shape Guide . See the example in the textbook Polyline and Polygon.

You can also read the corresponding blog post:

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

+2
source

Source: https://habr.com/ru/post/951883/


All Articles