title: Road/Route map between current location and searched location
body: <p>Here is code that execute road path or route path between 2 points<code>(origin, current location){geoPoint, "current Location"}</code> to <code>Destination.{geoPoint1, "Desti Location2"}</code>. It is working fine for me.</p>
  
  <p>My question is <strong>HOW TO DO ROAD PATH BETWEEN CURRENT LOCATION TO SEARCHED LOCATION</strong>. Here I am <code>onClick</code> of button searching location and it's showing perfectly, but I am geting error in road map between refer--> <code>{current location(scrgeoPoint)  to searched location(destgeopointsearch)}</code>.</p>
  
  <p>Anybody any ideas?</p>
  
  <pre><code> //search button onclick
       mapLocationBtn = (Button) findViewById(R.id.locationbutton);
       mapLocationBtn.setVisibility(View.INVISIBLE);
       mapLocationBtn.setOnClickListener(new View.OnClickListener() {              
              @Override
              public void onClick(View v) {           
                  String usrLoc = autoCompletetextView.getText().toString();
                  Geocoder gc = new Geocoder(PlacesMapActivity.this);                 
                  try {
                      addr=gc.getFromLocationName(usrLoc, 3);//maximum 2 results
                      if(addr.size()&gt;0){
                          address=addr.get(0);//get the first result
                          convertLongi=address.getLongitude();
                          convertLati=address.getLatitude();
                          geopointsearch = new GeoPoint((int)(convertLati * 1E6), (int)(convertLongi * 1E6));                                     
  
                       // Map geopointsearch overlay item
                          itemizedOverlay2 = new AddItemizedOverlay(drawable_client, PlacesMapActivity.this);     
                          overlayitem = new OverlayItem(geopointsearch, "Your Location3", "R u Searching For me!");
                          itemizedOverlay2.addOverlay(overlayitem);       
                          mapOverlays.add(itemizedOverlay2);
                          itemizedOverlay2.populateNow();
                          mc.animateTo(geopointsearch);   
                       //   mc.zoomIn();
                      }                       
                  } catch (IOException e) {                   
                      e.printStackTrace();
                  }
              }                                   
          });
  
      // Map overlay item
      itemizedOverlay = new AddItemizedOverlay(drawable_user, this);
      overlayitem = new OverlayItem(geoPoint, "Your Location","That is you!");
      itemizedOverlay.addOverlay(overlayitem);        
      mapOverlays.add(itemizedOverlay);
      itemizedOverlay.populateNow();      
      // Map client overlay item
      itemizedOverlay1 = new AddItemizedOverlay(drawable_client, this);       
      overlayitem1 = new OverlayItem(geoPoint1, "Your Location2", "I am ur client!");
      itemizedOverlay1.addOverlay(overlayitem1);              
      mapOverlays.add(itemizedOverlay1);
      itemizedOverlay1.populateNow();
      // Map near overlay item    
      itemizedOverlay = new AddItemizedOverlay(drawable, this);
  
      mc = mapView.getController();
  
      // These values are used to get map boundary area
      // The area where you can see all the markers on screen
      int minLat = Integer.MAX_VALUE;
      int minLong = Integer.MAX_VALUE;
      int maxLat = Integer.MIN_VALUE;
      int maxLong = Integer.MIN_VALUE;
  
      // check for null in case it is null
      if (nearPlaces.results != null) {
          // loop through all the places
          for (Place place : nearPlaces.results) {
              latitude = place.geometry.location.lat; // latitude
              longitude = place.geometry.location.lng; // longitude
  
              // Geopoint to place on map
              geoPoin = new GeoPoint((int) (latitude * 1E6),
                      (int) (longitude * 1E6));
  
              // Map overlay item
              overlayitem = new OverlayItem(geoPoin, place.name,
                      place.vicinity);
  
              itemizedOverlay.addOverlay(overlayitem);
  
              // calculating map boundary area
              minLat  = (int) Math.min( geoPoin.getLatitudeE6(), minLat );
              minLong = (int) Math.min( geoPoin.getLongitudeE6(), minLong);
              maxLat  = (int) Math.max( geoPoin.getLatitudeE6(), maxLat );
              maxLong = (int) Math.max( geoPoin.getLongitudeE6(), maxLong );
          }
          mapOverlays.add(itemizedOverlay);
  
          // showing all overlay items
          itemizedOverlay.populateNow();
      }
  
      DrawPath(geoPoint, geoPoint1, geopointsearch, Color.GREEN, mapView);
  
      // Adjusting the zoom level so that you can see all the markers on map
      mapView.getController().zoomToSpan(Math.abs( minLat - maxLat ), Math.abs( minLong - maxLong ));
  
      // Showing the center of the map
      mc.animateTo(new GeoPoint((maxLat + minLat)/2, (maxLong + minLong)/2 ));
      mc.animateTo(geoPoint1);
  
      mapView.postInvalidate();
  
  }   
  
  private void DrawPath(GeoPoint scrgeoPoint, GeoPoint destgeoPoint, GeoPoint destgeopointsearch, int green, MapView mMapView) {
       HttpClient httpclient = new DefaultHttpClient();
          HttpPost httppost = new HttpPost(makeUrl(scrgeoPoint, destgeoPoint, destgeopointsearch));
          HttpResponse response;
          try {
              response = httpclient.execute(httppost);
  
              HttpEntity entity = response.getEntity();
              InputStream is = null;
              is = entity.getContent();
              BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
              StringBuilder sb = new StringBuilder();
              sb.append(reader.readLine() + "\n");
              String line = "0";
              while ((line = reader.readLine()) != null) {
                  sb.append(line + "\n");
              }
              is.close();
              reader.close();
              String result = sb.toString();
              JSONObject jsonObject = new JSONObject(result);
              JSONArray routeArray = jsonObject.getJSONArray("routes");
              JSONObject routes = routeArray.getJSONObject(0);
  
              // calculate the distance between 2 point
              JSONArray legs = routes.getJSONArray("legs");
              Log.d("JSON","legs: "+legs.toString());
              JSONObject steps = legs.getJSONObject(0);
             Log.d("JSON","steps: "+steps.toString());
              JSONObject distance = steps.getJSONObject("distance");
              Log.d("JSON","distance: "+distance.toString());
              String sDistance = distance.getString("text");
              int iDistance = distance.getInt("value");                           
              distextView = (TextView) findViewById(R.id.distextView); 
              distextView.setText(distance.getString("text"));
  
              JSONObject overviewPolylines = routes.getJSONObject("overview_polyline");
              String encodedString = overviewPolylines.getString("points");
              List&lt;GeoPoint&gt; pointToDraw = decodePoly(encodedString);
              mMapView.getOverlays().add(new MyOverLay(pointToDraw));
  
              } catch (ClientProtocolException e) {            
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  
  private List&lt;GeoPoint&gt; decodePoly(String encoded) {
       List&lt;GeoPoint&gt; poly = new ArrayList&lt;GeoPoint&gt;();
          int index = 0, len = encoded.length();
          int lat = 0, lng = 0;
  
          while (index &lt; len) {
              int b, shift = 0, result = 0;
              do {
                  b = encoded.charAt(index++) - 63;
                  result |= (b &amp; 0x1f) &lt;&lt; shift;
                  shift += 5;
              } while (b &gt;= 0x20);
              int dlat = ((result &amp; 1) != 0 ? ~(result &gt;&gt; 1) : (result &gt;&gt; 1));
              lat += dlat;
  
              shift = 0;
              result = 0;
              do {
                  b = encoded.charAt(index++) - 63;
                  result |= (b &amp; 0x1f) &lt;&lt; shift;
                  shift += 5;
              } while (b &gt;= 0x20);
              int dlng = ((result &amp; 1) != 0 ? ~(result &gt;&gt; 1) : (result &gt;&gt; 1));
              lng += dlng;
  
              GeoPoint p = new GeoPoint((int) (((double) lat / 1E5) * 1E6),
                      (int) (((double) lng / 1E5) * 1E6));
              poly.add(p);
          }
          return poly;
      }
  
  private String makeUrl(GeoPoint scrgeoPoint, GeoPoint destgeoPoint, GeoPoint destgeopointsearch) {
      StringBuilder urlString = new StringBuilder();
  
      //Origin
      urlString.append("http://maps.googleapis.com/maps/api/directions/json");
      urlString.append("?origin=");// from
      urlString.append(Double.toString((double) scrgeoPoint.getLatitudeE6() / 1.0E6));
      urlString.append(",");
      urlString.append(Double.toString((double) scrgeoPoint.getLongitudeE6() / 1.0E6));
      //Destination
      urlString.append("&amp;destination=");// to
      urlString.append(Double.toString((double) destgeoPoint.getLatitudeE6() / 1.0E6));
      urlString.append(",");
      urlString.append(Double.toString((double) destgeoPoint.getLongitudeE6() / 1.0E6));
      //search location
      urlString.append("&amp;destination=");// to
      urlString.append(Double.toString((double) destgeopointsearch.getLatitudeE6() / 1.0E6));
      urlString.append(",");
      urlString.append(Double.toString((double) destgeopointsearch.getLongitudeE6() / 1.0E6));
  
  
      urlString.append("&amp;mode=walking&amp;sensor=true");             
      Log.d("xxx", "URL=" + urlString.toString());
      return urlString.toString();
  }
  </code></pre>