Here is my code
private var longitude = ""
private var latitude = ""
val lm = activity?.getSystemService(Context.LOCATION_SERVICE) as LocationManager?
if (ActivityCompat.checkSelfPermission(
requireActivity(),
Manifest.permission.ACCESS_FINE_LOCATION
) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(
requireActivity(),
Manifest.permission.ACCESS_COARSE_LOCATION
) != PackageManager.PERMISSION_GRANTED
) {
}
val location = lm!!.getLastKnownLocation(LocationManager.GPS_PROVIDER)
longitude = location!!.longitude.toString()
latitude = location.latitude.toString()
So location is null, How can I get my lat et long correctly in Kotlin?