title: How to show polylines on map
body: <p>I tried to show the polylines and it shows the correct line when I put it in <code>onLocationResult</code>. </p>
  
  <p>However, I only want it to show polylines when the user clicks on the start button. 
  So I tried to put the code into <code>onClickListener</code>, the screen only displays the marker but not the lines.</p>
  
  <pre><code>Location mLastLocation;
      LocationRequest mLocationRequest;
      private SupportMapFragment mapFragment;
      private FusedLocationProviderClient mFusedLocationClient;
      private FirebaseAuth myAuth;
      private FirebaseDatabase mDatabase;
      private DatabaseReference myRef;
      private Marker currentUserLocationMarker;
      private ArrayList&lt;LatLng&gt; points; //added
      Polyline line;
      private Button btnStartRun;
      LatLng latLng;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_googls_maps);
          // Obtain the SupportMapFragment and get notified when the map is ready to be used.
          SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                  .findFragmentById(R.id.map);
          mapFragment.getMapAsync(this);
  
          points = new ArrayList&lt;LatLng&gt;();
  
          mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
  
          btnStartRun=findViewById(R.id.btnStartRun);
  
          btnStartRun.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
  
                  points.add(latLng);//add points to the array
                  redrawLine();
  
                  myAuth=FirebaseAuth.getInstance();
                  DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference().child("OnlineUsers");//.child("OnlineUser");
                  DatabaseReference currentUserDB=mDatabase.child(myAuth.getCurrentUser().getUid());
                  currentUserDB.child("CurrentLatitude").setValue(mLastLocation.getLatitude());
                  currentUserDB.child("CurrentLongitude").setValue(mLastLocation.getLongitude());
              }
          }); 
      }
  </code></pre>
  
  <p>Here is my <code>onLocationResult</code></p>
  
  <pre><code> LocationCallback mLocationCallback = new LocationCallback() {
          @Override
          public void onLocationResult(LocationResult locationResult) {
              for (Location location : locationResult.getLocations()) {
                  mLastLocation = location;
  
                  latLng = new LatLng(location.getLatitude(), location.getLongitude());
  
                  mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
                  mMap.animateCamera(CameraUpdateFactory.zoomTo(15));
  
  
              }
          }
      };
  </code></pre>
  
  <p>Here is my <code>redrawline()</code></p>
  
  <pre><code>    private void redrawLine(){
  
          mMap.clear();  //clears all Markers and Polylines
  
          PolylineOptions options = new PolylineOptions().width(5).color(Color.BLUE).geodesic(true);//set the colour and width of the polyline
          for (int i = 0; i &lt; points.size(); i++) {
              LatLng point = points.get(i);
              options.add(point);
          }
          addMarker(); //add Marker in current position
          line = mMap.addPolyline(options); //add Polyline
      }
  </code></pre>
  
  <p>Thank you.</p>