title: Location always returning null all the time
body: <p>I am implementing a function to find my latitude and longitude but it keeps giving a null value.
  I declared android.permission.ACCESS_FINE_LOCATION, android.permission.ACCESS_BACKGROUND_LOCATION, android.permission.ACCESS_COARSE_LOCATION, and android.permission.INTERNET.</p>
  <p>I granted all permissions and it shows a 'granted' toast but why my location is always null?</p>
  <blockquote>
  <p>MainActivity</p>
  </blockquote>
  <pre><code>class MainActivity : AppCompatActivity() {
  
  private lateinit var binding: ActivityMainBinding
  private lateinit var fusedLocationProviderClient : FusedLocationProviderClient
  
  companion object {
      private const val PERMISSION_REQUEST_ACCESS_LOCATION = 100
  }
  
  override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      setContentView(R.layout.activity_main)
  
      fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this)
  
      getCurrentLocation()
  }
  
  private fun getCurrentLocation() {
      if( checkPermissions() )
      {
          if(isLocationEnabled())
          {
              if (ActivityCompat.checkSelfPermission(
                      this,
                      android.Manifest.permission.ACCESS_FINE_LOCATION
                  ) != PackageManager.PERMISSION_GRANTED &amp;&amp; ActivityCompat.checkSelfPermission(
                      this,
                      android.Manifest.permission.ACCESS_COARSE_LOCATION
                  ) != PackageManager.PERMISSION_GRANTED
              ){
                  requestPermission()
                  return
              }
  
              fusedLocationProviderClient.lastLocation.addOnCompleteListener(this) { task -&gt;
                  val location : Location? = task.result
                  if(location == null)
                  {
                      Toast.makeText(this, &quot;Null Received&quot;, Toast.LENGTH_SHORT).show()
                  }
                  else
                  {
                      Toast.makeText(this, &quot;Get Success&quot;, Toast.LENGTH_SHORT).show()
                      binding.txtLat.text = &quot;&quot;+location.latitude
                      binding.txtLong.text = &quot;&quot;+location.longitude
                  }
              }
          }
          else
          {
              Toast.makeText(this, &quot;Turn on location&quot;, Toast.LENGTH_SHORT).show()
              val intent = Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)
              startActivity(intent)
          }
      }
      else
      {
          //request permission here
          requestPermission()
      }
  }
  
  private fun isLocationEnabled() : Boolean {
      val locationManager : LocationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager
      return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
              || locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
  }
  
  private fun requestPermission() {
      ActivityCompat.requestPermissions(
          this, arrayOf(android.Manifest.permission.ACCESS_COARSE_LOCATION,
          android.Manifest.permission.ACCESS_FINE_LOCATION), PERMISSION_REQUEST_ACCESS_LOCATION
      )
  }
  
  private fun checkPermissions() : Boolean
  {
      if(ActivityCompat.checkSelfPermission(this,
          android.Manifest.permission.ACCESS_COARSE_LOCATION)
      ==PackageManager.PERMISSION_GRANTED &amp;&amp; ActivityCompat.checkSelfPermission(this,
          android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)
      {
          return true
      }
      return false
  }
  
  override fun onRequestPermissionsResult(
      requestCode: Int,
      permissions: Array&lt;out String&gt;,
      grantResults: IntArray
  ) {
      super.onRequestPermissionsResult(requestCode, permissions, grantResults)
  
      if(requestCode ==  PERMISSION_REQUEST_ACCESS_LOCATION){
          if(grantResults.isNotEmpty() &amp;&amp; grantResults[0] == PackageManager.PERMISSION_GRANTED)
          {
              Toast.makeText(applicationContext, &quot;Granted&quot;, Toast.LENGTH_SHORT).show()
              getCurrentLocation()
          }
  
          else {
              Toast.makeText(applicationContext, &quot;Denied&quot;, Toast.LENGTH_SHORT).show()
          }
      }
  }
  }
  </code></pre>