Created
September 4, 2019 20:34
-
-
Save mayowa-egbewunmi/41579edbdc553e916f81e5e1ffe30af3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LocationLiveData(context: Context) : LiveData<LocationModel>() { | |
private var fusedLocationClient = LocationServices.getFusedLocationProviderClient(context) | |
override fun onInactive() { | |
super.onInactive() | |
fusedLocationClient.removeLocationUpdates(locationCallback) | |
} | |
@SuppressLint("MissingPermission") | |
override fun onActive() { | |
super.onActive() | |
fusedLocationClient.lastLocation | |
.addOnSuccessListener { location: Location? -> | |
location?.also { | |
setLocationData(it) | |
} | |
} | |
startLocationUpdates() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment