title: How to add Google Map Markers outside of onMapReady() in Android?
body: <p>I have the following function that returns me the current location of device:</p>
  
  <pre><code>void getCurrentLocation()
  {
      Location myLocation  = map.getMyLocation();
      if(myLocation!=null)
      {
          double dLatitude = myLocation.getLatitude();
          double dLongitude = myLocation.getLongitude();
          map.addMarker(new MarkerOptions().position(new LatLng(dLatitude, dLongitude))
                  .title("My Location").icon(BitmapDescriptorFactory
                          .defaultMarker(BitmapDescriptorFactory.HUE_RED)));
          map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(dLatitude, dLongitude), 8));
  
      }
      else
      {
          Toast.makeText(this, "Unable to fetch the current location", Toast.LENGTH_SHORT).show();
      }
  }
  </code></pre>
  
  <p>but some methods are showing in red like it were undefined:
  <a href="https://i.stack.imgur.com/6uOw3.png" rel="noreferrer"><img src="https://i.stack.imgur.com/6uOw3.png" alt="this"></a></p>
  
  <p>As you can notice, these methods are related with map, it work in onMapReady() function but out of it show it unrecognized. Why is that? What libraries I have to add? I declare map like this:</p>
  
  <pre><code>private MapFragment map;
  </code></pre>