Using the same function:
private fun getAddress(lat: LatLng): String? {
val geocoder = Geocoder(this)
val list = geocoder.getFromLocation(lat.latitude, lat.longitude,1)
return list[0].getAddressLine(0)
}
I’ve solved. Only I converted the objetcs to LatLng data. and I encapsulated to my mapOnReady
If anyone has the same issue this is my mapOnReady code:
mMap.setOnMapLongClickListener { latlng →
//mMap.clear(); -Let only one marker
mMap.animateCamera(CameraUpdateFactory.newLatLng(latlng))
//mMap.setOnInfoWindowClickListener()
getcoordinates = LatLng(latlng.latitude, latlng.longitude) //catch coordinates from maps API
val markerOptions = MarkerOptions().position(getcoordinates)
/*val titlesr = getAddress(getcoordinates)
markerOptions.title(titlesr)*/
val titlesr = getAddress(getcoordinates)
markerOptions.title(titlesr)
//.title(mMap.addMarker(markerOptions).toString()))
mMap.addMarker(MarkerOptions()
.position(getcoordinates)
//.title(getcoordinates.toString()) -->ONLY SHOW THE LATITUDE AND LONGITUDE
.title(getAddress(getcoordinates))
.snippet("La ubicación puede ser precisa más no exacta."))
//.title("Hola") --Basic marker interaction with user
}
And put correctly the objects with correct encapsulation, and declaration on each other.
Thank you.