ViewModel property is empty even after initializing it

43 Views Asked by At

I have a program, where user is being asked for granting location permissions, location service. After that, in the ViewModel user current geo location should be saved in MutableLiveData. In other function these geo location should be displayed in console. Turns out, it is empty, somehow. Where I've made a mistake?

ViewModel

    fun location(){
    viewModelScope.launch {
        val testLocation = locationRequest.getCurrentLocation()
        testLocation.let {
            _location.postValue(mutableMapOf("lat" to (it?.latitude ?: 00.00),
                "lon" to (it?.longitude ?: 00.00)))
        }
    }
}
fun test(){
    viewModelScope.launch {
        println("TEST ELSE ${location?.values}")
    }
}

this code is run after granting location permissions, and turning on location service

0

There are 0 best solutions below