title: plot a route on google maps, android
body: <p>I want to draw a route on google map with the change in my position using GPS. As my location changes(when new geopoints are created), the dot moves on the google map but i'm unable to draw the line on the map. </p>
  
  <p>Please help in plotting the route on google maps. Below is my code</p>
  
  <p>`</p>
  
  <pre><code>LocationManager locman;
  LocationListener loclis;
  Location location;
  private MapView map;
  
  List&lt;GeoPoint&gt; geoPointsArray = new ArrayList&lt;GeoPoint&gt;();
  private MapController controller;
  String provider = LocationManager.GPS_PROVIDER;
  double lat;
  double lon;
  
  
  @Override
     public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        initMapView();
        initMyLocation();
        locman = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
        //locman.requestLocationUpdates(provider,60000, 100,loclis);
        //Location = locman.getLastKnownLocation(provider);
  
     }
  /** Find and initialize the map view. */
     private void initMapView() {
        map = (MapView) findViewById(R.id.mapView);
        controller = map.getController();
        map.setSatellite(false);
        map.setBuiltInZoomControls(true);
     }
  
     /** Find Current Position on Map. */
     private void initMyLocation() {
        final MyLocationOverlay overlay = new MyLocationOverlay(this, map);
        overlay.enableMyLocation();
        overlay.enableCompass(); // does not work in emulator
        overlay.runOnFirstFix(new Runnable() {
           public void run() {
              // Zoom in to current location
              controller.setZoom(16);
              controller.animateTo(overlay.getMyLocation());
           }
        });
        map.getOverlays().add(overlay);
     }
  
  public void onLocationChanged(Location location) {
      if (location != null){
          lat = location.getLatitude();
          lon = location.getLongitude();
          GeoPoint New_geopoint = new GeoPoint((int)(lat*1e6),(int)(lon*1e6));
          controller.animateTo(New_geopoint);
  
      }
  
  }
  class MyOverlay extends Overlay{
      public MyOverlay(){
      }   
      public void draw(Canvas canvas, MapView mapv, boolean shadow){
      super.draw(canvas, mapv, shadow);
      Paint paint;
      paint = new Paint();
      paint.setColor(Color.GREEN);
  
      paint.setAntiAlias(true);
      paint.setStyle(Style.STROKE);
      paint.setStrokeWidth(3);
  
          Projection projection = map.getProjection();
          Path p = new Path();
          for (int i = 0; i &lt; geoPointsArray.size(); i++) {
              if (i == geoPointsArray.size() - 1) {
                  break;
              }
          Point from = new Point();
          Point to = new Point();
          projection.toPixels(geoPointsArray.get(i), from);
          projection.toPixels(geoPointsArray.get(i + 1), to);
          p.moveTo(from.x, from.y);
  
          canvas.drawLine(from.x, from.y, to.x, to.y, paint);
              }
         }
   }
  
      `
  </code></pre>