user1517638
user1517638

Reputation: 982

how to customize the polyline in google map

In my application I integrated google map with travel path. Currently I am using polyline to draw a path between source and destination. My query is I want to change the line into hyphen (-). I searched but I didn't get a solution. please help me, thanks in advance. enter image description here

Upvotes: 3

Views: 4636

Answers (1)

Nine To Four
Nine To Four

Reputation: 91

Now in Polyline you can set the pattern to be Dash, Dot or Gap simply apply the following:

public static final int PATTERN_DASH_LENGTH_PX = 20;
public static final int PATTERN_GAP_LENGTH_PX = 20;
public static final PatternItem DOT = new Dot();
public static final PatternItem DASH = new Dash(PATTERN_DASH_LENGTH_PX);
public static final PatternItem GAP = new Gap(PATTERN_GAP_LENGTH_PX);
public static final List<PatternItem> PATTERN_POLYGON_ALPHA = Arrays.asList(GAP, DASH);

 ...
 PolylineOptions polylineOptions = new PolylineOptions()
                .geodesic(true)
                .color(Color.CYAN)
                .width(10)
                .pattern(PATTERN_POLYGON_ALPHA);
        polylineOptions.addAll(route.getPoints());
        polylinePaths.add(mGoogleMap.addPolyline(polylineOptions));
 ...

Demo

Upvotes: 6

Related Questions