title: How to get coordinate from fixed marker at center of google maps in android
body: <p>In my application I'm trying to get coordinate from fixed marker at center of google maps. When i scroll map, i want to get coordinate and set it on the text view.</p>
  
  <p>Here is my Kotlin code:</p>
  
  <pre><code>class ActivityMapsDSPBng : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnMarkerClickListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener,
          com.google.android.gms.location.LocationListener {
  
      ...
  
      private val TAG = "ActivityMapsDSPBng"
      private lateinit var mGoogleApiClient: GoogleApiClient
      private var mLocationManager: LocationManager? = null
      lateinit var mLocation: Location
      private var mLocationRequest: LocationRequest? = null
      private val listener: com.google.android.gms.location.LocationListener? = null
      private val UPDATE_INTERVAL = (2 * 1000).toLong()
      private val FASTEST_INTERVAL: Long = 2000
  
      lateinit var locationManager: LocationManager
  
      override fun onStart() {
          ...
      }
  
      override fun onStop() {
          ...
      }
  
      override fun onConnectionSuspended(p0: Int) {
          ...
      }
  
      override fun onConnectionFailed(connectionResult: ConnectionResult) {
          Log.i(TAG, "Connection failed. Error: " + connectionResult.errorCode)
      }
  
      override fun onLocationChanged(location: Location) {
          var msg = "Update Location: Latitude " + location.latitude.toString() + " Longitude " + location.longitude.toString()
          tv_dspbg_lat.setText("" + location.latitude)
          tv_dspbg_long.setText("" + location.longitude)
          Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
      }
  
      override fun onConnected(p0: Bundle?) {
          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) {
              return
          }
  
          startLocationUpdates()
  
          var fusedLocationProviderClient: FusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this)
          fusedLocationProviderClient.lastLocation
                  .addOnSuccessListener(this, OnSuccessListener&lt;Location&gt; { location -&gt;
                      if (location != null){
                          mLocation = location
                          tv_dspbg_lat.setText("" + mLocation.latitude)
                          tv_dspbg_long.setText("" + mLocation.longitude)
                      }
                  })
      }
  
      protected fun startLocationUpdates(){
          // Create location request
          mLocationRequest = LocationRequest.create()
                  .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
                  .setInterval(UPDATE_INTERVAL)
                  .setFastestInterval(FASTEST_INTERVAL)
  
          // Request location updates
          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){
              return
          }
          LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this)
      }
  
      override fun onCreate(savedInstanceState: Bundle?) {
          ...
  
          val mapsDSPBNGfragment = supportFragmentManager
                  .findFragmentById(R.id.maps_dspbg) as SupportMapFragment
          mapsDSPBNGfragment.getMapAsync(this)
  
          fusedLPCBg = LocationServices.getFusedLocationProviderClient(this)
  
          mGoogleApiClient = GoogleApiClient.Builder(this)
                  .addConnectionCallbacks(this)
                  .addOnConnectionFailedListener(this)
                  .addApi(LocationServices.API)
                  .build()
          mLocationManager = this.getSystemService(Context.LOCATION_SERVICE) as LocationManager
  
          checkLocation()
      }
  
      private fun checkLocation(): Boolean{
          ...
      }
  
      private fun isLocationEnabled(): Boolean{
          ...
      }
  
      private fun showAlert(){
          val dialog = AlertDialog.Builder(this)
          dialog.setTitle("Enable Location")
                  .setMessage("Your location setting is set to 'Off'. \nPlease enable location to " + "use this app")
                  .setPositiveButton("Location Settings", DialogInterface.OnClickListener { paramDialogInterface, paramInt -&gt;
                      val myIntent = Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)
                      startActivity(myIntent)
                  })
                  .setNegativeButton("Cancel", DialogInterface.OnClickListener { paramDialogInterface, paramInt -&gt;  })
          dialog.show()
      }
  
  }
  </code></pre>
  
  <p>I build code from <a href="https://androidteachers.com/kotlin-for-android/get-location-in-android-with-kotlin/" rel="nofollow noreferrer">https://androidteachers.com/kotlin-for-android/get-location-in-android-with-kotlin/</a></p>
  
  <p>When I scrool maps, coordinates do not change according to the fixed maker.</p>