title: Get current(not last) location with update only one time in Android
body: <p>I want to get current location when I touch a button.</p>
  
  <ol>
  <li><p>Touch a button</p></li>
  <li><p><strong>requestLocationUpdates</strong> one time, and get current location, then <strong>removeLocationUpdates</strong>.</p></li>
  </ol>
  
  <p>The problem is in 2. I don't want GPS and wifi work all time when I <strong>requestLocationUpdates</strong>. But I don't know how to <strong>removeLocationUpdates</strong> in
  <strong>locationCallback</strong>.</p>
  
  <pre><code>package com.example.location
  
  import android.annotation.SuppressLint
  import android.content.pm.PackageManager
  import android.support.v7.app.AppCompatActivity
  import android.os.Bundle
  import android.support.v4.app.ActivityCompat
  import android.util.Log
  import android.widget.Button
  import android.widget.TextView
  import com.google.android.gms.location.*
  
  class MainActivity : AppCompatActivity() {
  
  
  private var userAgreePermissionCode = 1
  
  
  private lateinit var userLocationClient: FusedLocationProviderClient
  
  
  private lateinit var userLocationCallback: LocationCallback
  
  @SuppressLint("RestrictedApi")
  override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      setContentView(R.layout.activity_main)
  
  
      val somePermission = arrayOf(android.Manifest.permission.ACCESS_COARSE_LOCATION, android.Manifest.permission.ACCESS_FINE_LOCATION)
      for (p in somePermission ){
          if(ActivityCompat.checkSelfPermission(this, p) != PackageManager.PERMISSION_GRANTED)
              ActivityCompat.requestPermissions(this, somePermission , userAgreePermissionCode)
          break
      }
  
  
      findViewById&lt;Button&gt;(R.id.Locate).setOnClickListener{
  
  
          userLocationClient = LocationServices.getFusedLocationProviderClient(this)
  
  
          val userLocationRequest = LocationRequest().apply {
              interval = 1000  
              fastestInterval = 1000
              priority = LocationRequest.PRIORITY_HIGH_ACCURACY
          }
  
          //  Problem is here
          userLocationCallback = object : LocationCallback() {
              override fun onLocationResult(locationResult: LocationResult?) {
                  locationResult ?: return
                  for (location in locationResult.locations){
  
                      //  I want to get the first update location(current location) and close requestLocationUpdates!!!!
                      //  Only one time, not keep update
                      Log.i("longitude", location.longitude.toString())
                      Log.i("latitude", location.latitude.toString())
                      //  findViewById&lt;TextView&gt;(R.id.Longitude).text = location.longitude.toString()
                      //  findViewById&lt;TextView&gt;(R.id.Latitude).text = location.latitude.toString()
  
                      //  Problem here, it's error.
                      userLocationClient.removeLocationUpdates(userLocationCallback)
                  }
              }
          }
  
  
          userLocationClient.requestLocationUpdates(userLocationRequest,userLocationCallback,null)
  
      }
  }
  
  //  -----------------------------------------
  override fun onRequestPermissionsResult(requestCode: Int, permissions: Array&lt;String&gt;, grantResults: IntArray) {
      when (requestCode) {
          userAgreePermissionCode -&gt; {
              for( i in 0..(grantResults.size-1) ){
                  if ((grantResults.isNotEmpty() &amp;&amp; grantResults[i] == PackageManager.PERMISSION_GRANTED))
                      Log.i("Status:", "Agree a permission")
                  else
                      finish()
              }
              return
          }
      }
  }
  //  -----------------------------------------
  </code></pre>
  
  <p>}</p>