I saw other questions / answers about this that use markers and rotate them. But there is an easier way to have direction arrows on the GoogleMap Polyline.
The GoogleMap API v2 provides a convenient way to do this by adding the " endcap " icon to PolylineOptions. It takes your bitmap icon and rotates it in the direction of your polyline. Arrows do not need markers. And rotate the icon automatically. While the original arrow icon points up.
Honestly, I am surprised that there is no ArrowCap class. These classes exist: ButtCap , RoundCap , SquareCap , but not the ArrowCap class.
So, we need to break through it with our own arrow image. The only minor issue is that Polyline (and the next connected Polyline) uses the CENTER of the icon as the endpoint. Therefore, make sure that the icon of your butt is in the center of the image.
I made and uploaded a sample arrow image here: <
>
Sorry that it is white and looks invisible, but it exists between <>, just drag it to the desktop.
I wanted to be able to change the color of the arrow programmatically, so I created this white PNG image and then used the color filter to overlay (MULTIPLY) the colors on it.
The icon is a white arrow pointing up with a dot in the CENTER of the image. The upper half of the image is empty (transparent). You want to use Image Asset Studio (or your favorite image tool) to create mipmap images for these resolutions: mdpi = 24x24, hdpi = 36x36, xhdpi = 48x48, xxhdpi = 72x72, xxxhdpi = 96x96.
Here is the code to create the final BitmapDescriptor file needed for Polyline / PolylineOptions ( R.mipmap.endcap is the image I included above):
public BitmapDescriptor getEndCapIcon(Context context, int color) {
And here is the code for creating the Polyline with an arrow outline that points towards the Polyline:
public Polyline drawPolylineWithArrowEndcap(Context context, GoogleMap googleMap, LatLng fromLatLng, LatLng toLatLng) { int arrowColor = Color.RED;