3

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

user1517638
  • 972
  • 1
  • 10
  • 16
  • Did you read https://developers.google.com/maps/terms 10.4.c.iii? – Prexx Oct 02 '15 at 11:25
  • yes, but I didn't get a solution – user1517638 Oct 02 '15 at 11:39
  • Possible duplicate of [How to draw dashed polyline with android google map sdk v2?](http://stackoverflow.com/questions/13721008/how-to-draw-dashed-polyline-with-android-google-map-sdk-v2) – Andy Oct 05 '15 at 17:35
  • Definitely do-able with [javascript libary](https://developers.google.com/maps/documentation/javascript/examples/overlay-symbol-dashed), if you want to draw inspiration from that. – Andy Oct 05 '15 at 17:36
  • is it possible to implement JavaScript in google map – user1517638 Oct 07 '15 at 08:48

1 Answers1

6

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

isherwood
  • 58,414
  • 16
  • 114
  • 157
Nine To Four
  • 91
  • 1
  • 7