Skip to content

Instantly share code, notes, and snippets.

@mayowa-egbewunmi
Created September 4, 2019 20:34
Show Gist options
  • Select an option

  • Save mayowa-egbewunmi/41579edbdc553e916f81e5e1ffe30af3 to your computer and use it in GitHub Desktop.

Select an option

Save mayowa-egbewunmi/41579edbdc553e916f81e5e1ffe30af3 to your computer and use it in GitHub Desktop.
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