title: How to draw dotted polylines using Google Maps - Android
body: <p>I have noticed that iOS has a built in function to draw dotted polylines using Google Maps, but I am unable to find the equivalent for Android. The idea is that iOS can set two colors, one being the color of the line and the other being the space between (transparent) and this will create dotted lines. iOS implementation looks like this</p>
  
  <pre><code>- (GMSPolyline )drawDashPath:(GMSPath ) path{
      GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
      polyline.map = self.googleMapView;
      polyline.strokeWidth = 5.0;
      NSArray *styles = @[[GMSStrokeStyle solidColor:[UIColor blueColor]],[GMSStrokeStyle solidColor:[UIColor clearColor]]];
      NSArray *lengths = @[@5, @5];
      polyline.spans = GMSStyleSpans(polyline.path, styles, lengths, kGMSLengthRhumb);
      return polyline;
  }
  </code></pre>
  
  <p>For Android, I have achieved dotted lines, but I had to do it using calculations and manipulation. Here is what I am doing for Android</p>
  
  <pre><code>                // calculate the difference in latitude and longitude between start and end points
                  double difLat = latLngDest.latitude - latLngOrig.latitude;
                  double difLng = latLngDest.longitude - latLngOrig.longitude;
  
                  // retrieve current zoom level
                  double zoom = mMap.getCameraPosition().zoom;
  
                  // come up with distance between dotted lines that adjusts according to zoom levels
                  double divLat = difLat / (zoom * 1.2);
                  double divLng = difLng / (zoom * 1.2);
                  LatLng tmpLatOri = latLngOrig;
  
                  // add polyline to list
                  for (int i = 0; i &lt; (zoom * 1.2); i++) {
                      LatLng loopLatLng = tmpLatOri;
  
                      if (i &gt; 0) {
                          loopLatLng = new LatLng(tmpLatOri.latitude + (divLat * 0.40f), tmpLatOri.longitude + (divLng * 0.40f));
                      }
  
                      polylineList.add(mMap.addPolyline(new PolylineOptions()
                                      .add(loopLatLng)
                                      .add(new LatLng(tmpLatOri.latitude + divLat, tmpLatOri.longitude + divLng))
                                      .color(Utils.getColor(mContext, R.color.orange))
                                      .width(18f)));
                      tmpLatOri = new LatLng(tmpLatOri.latitude + divLat, tmpLatOri.longitude + divLng);
                   }
  </code></pre>
  
  <p>This looks OK, but I rather use a built in function if it exists. I have looked over the documentation and am unable to find anything for Android.</p>