title: How to draw path on Google Map road according to given coordinates?
body: <p>I am trying to draw a path on roads and follow some given points.I am using Google Directions API to follow the roads.I put some markers on roads and link these points with polylines.But not all points were linked.Sometimes all points were drawn sometimes some of them is missing.I could’t understand why?
      <img src="https://i.stack.imgur.com/iD71W.png" alt=""><br>
  MyList is an array which consists of lat lng values of some points.latlngBoundsfunction links elements of that array in a for loop.</p>
  
  <pre><code>            for (int i = 0; i &lt; myList.size(); i++) {
  
              Double latS = Double.parseDouble(myList.get(i).getlat());
              Double lngS = Double.parseDouble(myList.get(i).getlng());
  
              Double latD = Double.parseDouble(myList.get(i+1).getlat());
              Double lngD = Double.parseDouble(myList.get(i+1).getlng());
  
              LatLng first = new LatLng(latS,lngS);
              LatLng second = new LatLng(latD,lngD);
  
              findDirections(latS,lngS,latD,lngD, GMapV2Direction.MODE_DRIVING );  
              latlngBounds = createLatLngBoundsObject(first,second);
              }
  
      public void findDirections(double fromPositionDoubleLat, double fromPositionDoubleLong,              double toPositionDoubleLat, double toPositionDoubleLong, String mode)
  {
      Map&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
      map.put(GetDirectionsAsyncTask.USER_CURRENT_LAT, String.valueOf(fromPositionDoubleLat));
      map.put(GetDirectionsAsyncTask.USER_CURRENT_LONG, String.valueOf(fromPositionDoubleLong));
      map.put(GetDirectionsAsyncTask.DESTINATION_LAT, String.valueOf(toPositionDoubleLat));
      map.put(GetDirectionsAsyncTask.DESTINATION_LONG, String.valueOf(toPositionDoubleLong));
      map.put(GetDirectionsAsyncTask.DIRECTIONS_MODE, mode);
  
      GetDirectionsAsyncTask asyncTask = new GetDirectionsAsyncTask(this);
      asyncTask.execute(map); 
  }
  
      public void handleGetDirectionsResult(ArrayList&lt;LatLng&gt; directionPoints) {
          PolylineOptions rectLine = new PolylineOptions().width(5).color(Color.BLUE);
  
          for(int i = 0 ; i &lt; directionPoints.size() ; i++) 
          {          
              rectLine.add(directionPoints.get(i));
          }
          newPolyline = googleMap.addPolyline(rectLine);
  
  
  }
  </code></pre>
  
  <p>I make use of two class  of this source in the link <a href="http://blog-emildesign.rhcloud.com/?p=822" rel="nofollow noreferrer">GMapV2Direction,GetDirectionsAsyncTask</a></p>