title: how to fetch current location with permission android kotlin
body: <p>I'm back after a while to android development. I want to have my current latitude and longitude and display it with a toast, unfortunately, it doesn't work . I added location permissions in AndroidManifest.xml</p>
  <pre><code>&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.ACCESS_FINE_LOCATION&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.ACCESS_COARSE_LOCATION&quot;/&gt;
  </code></pre>
  <p>And here is my MainActivity.kt :</p>
  <pre><code>class MainActivity : AppCompatActivity() {
      
      private lateinit var fusedLocationClient: FusedLocationProviderClient
          
          override fun onCreate(savedInstanceState: Bundle?) {
              super.onCreate(savedInstanceState)
              setContentView(R.layout.activity_main)
              fusedLocationClient = LocationServices.getFusedLocationProviderClient(this)
              fetchLocation()
          }
      
          override fun onStart() {
              super.onStart()
              fetchLocation()
          }
      
          private fun fetchLocation() {
              val task: Task&lt;Location&gt; = fusedLocationClient.lastLocation
              if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)!=PackageManager.PERMISSION_GRANTED &amp;&amp; 
              ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)!= PackageManager.PERMISSION_GRANTED
              ){
                 ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), 101)
                  return
              }
              task.addOnSuccessListener {
                  if (it != null){
                      Toast.makeText(this, &quot;${it.latitude} - ${it.longitude}&quot;, Toast.LENGTH_SHORT).show()
                      Log.d(&quot;LOCATION&quot;, &quot;${it.latitude} - ${it.longitude}&quot;)
                  }
              }
      
          }
      }
  </code></pre>
  <p>My question is why the function fetchLocation() isn't triggering after accepting permission and activating the GPS. Help me please!!!</p>