title: Kotlin Why can't I change my variables in my onCompleteListener
body: <p>I'm trying to make an android google maps app and I'm having trouble with the global variables I assign values to inside the listener not being completed. In this case, I'm trying to store the current location of the device after setting a marker there, and the documentation said to use a listener. The problem is, the values reset to their previous values after the listener is complete, and I can't return from inside the listener.</p>
  <p>Here's the variable, it's not private right now because I was testing if it affected it for some reason:</p>
  <pre><code>lateinit var latLng : LatLng
  </code></pre>
  <p>Here's the function causing the problems:</p>
  <pre><code>private fun setDestinations() : LatLng{
      checkPermission()
      var locationResult = fusedLocationProviderClient.lastLocation;
      var lat = 0.0
      var lng = 0.0
          locationResult.addOnCompleteListener(this) { task -&gt;
              if(task.isSuccessful){
                  lng = locationResult.result.longitude
                  lat = locationResult.result.latitude
                  latLng = LatLng(lat, lng)
                  setBaseLocation(lat, lng)
                  /**debug**/
                  println(&quot;First: $lat $lng&quot;)
              } else {
                  Toast.makeText(this, &quot;Cannot retrieve location&quot;, Toast.LENGTH_LONG).show()
              }
          }
      println(&quot;Third: &quot; + latLng.latitude + &quot; &quot; +  latLng.latitude)
      return latLng
  }
  </code></pre>
  <p>I get thrown an error when it reaches return saying that <code>latLng</code> has not been initialized</p>
  <p>please help me if you can, I really need it</p>