Question

I tried to find a way to draw a dashed line for the polyline I need in my application, but the only style parameters that PolyLineOptions allows you to change are: color and width. I kept on searching on google and kept hearing of "Symbols" But as far as I understood this is only for Javascript. Is there a possibility to somehow draw the line for my polyline as a dashed line or dotted one? Also I've seen that on the iOS it is possible, should then android also have a similar function?

Was it helpful?

Solution

I'm afraid this answer wont suit you:

Currently there is no easy way of doing this on Google Maps v2. If you want to use the tools provided by Google you must split your Polyline in to several small ones, this SO question has a example: How to draw dashed polyline with android google map sdk v2?

If you really want dashed lines and need to draw many (really many) I would suggest creating a overlay and draw on that instead and move it with the map. However it isn't an easy approach considering e.g scaling and rotating of the map. But for small - medium amount of dashed lines it is not worth the pain.

There will likely be a dashed feature in Google Maps V3 considering that Google Maps JS v3 has it.

OTHER TIPS

In February 2017 Google released a new set of customizations for polylines and polygons in Google Maps Android API v2.

See information about new features in the Shapes Guide. See an example in the Polylines and Polygons tutorial.

You can also read the corresponding blog post here:

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

// Set a Stroke pattern [Add dots dashes and spaces as per your requirement]
List<PatternItem> pattern = Arrays.<PatternItem>asList(new Dot(), new Gap(20), new Dash(30), new Gap(20));

// Intialize PolylineOptions
PolylineOptions lineOptions = new PolylineOptions();

// set the pattern to polylineOptions like you set color,width etc.
lineOptions.setPattern(pattern);

// Add the polyline to map passing PolylineOptions
map.addPolyline(lineOptions);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top