title: Draw a polyline after every 10 seconds on google map in andriod
body: <p>I have made an application in which user's location is fetched after every 10 seconds once the start button is pressed and a polyline is drawn from old to new location untill stop button is pressed. 
  now the problem is when the polyline code is inside the run function, there is no line drawn on the map. but if i put that code outside the run function, it is working fine (like when i re-presss the start button i get the polyline) but i don't want to press the button every single time, i want that line to be drawn on it's own through a timer.</p>
  
  <p>here is my code</p>
  
  <pre><code>    track_record.setOnClickListener(new View.OnClickListener() {
                                              @Override
                                              public void onClick(View v) {
                                                  Toast.makeText(getApplication(), "Your Tracking is started now", Toast.LENGTH_SHORT).show();
                                                  ///////*************************************////////
                                                  // create class object
                                                  gps = new GPSTracker(MapsActivity.this);
                                                  timer.scheduleAtFixedRate(new TimerTask() {
  
                                                      @SuppressLint("DefaultLocale")
                                                      @TargetApi(Build.VERSION_CODES.GINGERBREAD)
                                                      @Override
  
                                                      public void run() {
                                                          runOnUiThread(new Runnable() {
                                                              @Override
                                                              public void run() {
  
                                                                  LatLng current =   new LatLng(latitude = gps.getLatitude(),longitude = gps.getLongitude());
  
                                                                  if (begin == 0) {
                                                                 fixedBegin = current;
  
                                                                      // create marker
                                                                      MarkerOptions marker = new MarkerOptions().position(fixedBegin).title("Begin ");
  
                                                                      // Changing the color babyyy
                                                                    marker.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
                                                                      // adding marker
                                                                  mMap.addMarker(marker);
  
  
                                                                      // Not working here, but should be
  
                                                                      if(Flag==0)  //when the first update comes, we have no previous points,hence this
                                                                      {
                                                                          prev=current;
                                                                          Flag=1;
                                                                      }
                                                                      CameraUpdate update = CameraUpdateFactory.newLatLngZoom(current, 16);
                                                                      mMap.animateCamera(update);
                                                                      mMap.addPolyline((new PolylineOptions())
                                                                              .add(prev, current).width(6).color(Color.BLUE)
                                                                              .visible(true));
                                                                      prev=current;
                                                                      current = null;
  
                                                                }
                                                                  begin++;
  
                                                                  Log.i("OK", "lat------ " + latitude);
                                                                  Log.i("OK", "lng-------- " + longitude);
  
                                                                  arrLat.add(latitude);
                                                                  arrLng.add(longitude);
  
                                                                  //////////// TRYING ///////////
                                                                  // And it Worked here
  
  /*
                                                                  if(Flag==0)  //when the first update comes, we have no previous points,hence this
                                                                  {
                                                                      prev=current;
                                                                      Flag=1;
                                                                  }
                                                                  CameraUpdate update = CameraUpdateFactory.newLatLngZoom(current, 16);
                                                                  mMap.animateCamera(update);
                                                                  mMap.addPolyline((new PolylineOptions())
                                                                          .add(prev, current).width(6).color(Color.BLUE)
                                                                          .visible(true));
                                                                  prev=current;
                                                                  current = null;
  */
  
  
                                                              }
                                                          });
  
  
                                                      }
                                                  }, 0, TIME_INTERVAL);
  
  
                                                  // check if GPS enabled
                                                  if (gps.canGetLocation()) {
  
                                                      latitude = gps.getLatitude();
                                                      longitude = gps.getLongitude();
                                                      String longlat = String.valueOf(latitude) + ":" + String.valueOf(longitude);
                                                      cordsList.add(longlat);
                                                      // \n is for new line
                                                      Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();
                                                  } else {
                                                      Toast.makeText(getApplicationContext(), "Sorry cant get location", Toast.LENGTH_LONG).show();
                                                      // can't get location
                                                      // GPS or Network is not enabled
                                                      // Ask user to enable GPS/network in settings
                                                      // gps.showSettingsAlert();
                                                  }
  
                                                  Log.i("Finall", "Location-&gt; " + cordsList.toString());
  
                                              }
                                          }
          );
  </code></pre>