Skip to content

Instantly share code, notes, and snippets.

View mayowa-egbewunmi's full-sized avatar

Egbewunmi Mayowa mayowa-egbewunmi

View GitHub Profile
class LocationLiveData(context: Context) : LiveData<LocationModel>() {
@SuppressLint("MissingPermission")
private fun startLocationUpdates() {
fusedLocationClient.requestLocationUpdates(
locationRequest,
locationCallback,
null
)
}
class LocationLiveData(context: Context) : LiveData<LocationModel>() {
private val locationCallback = object : LocationCallback() {
override fun onLocationResult(locationResult: LocationResult?) {
locationResult ?: return
for (location in locationResult.locations) {
setLocationData(location)
}
}
}
class LocationLiveData(context: Context) : LiveData<LocationModel>() {
companion object {
val locationRequest: LocationRequest = LocationRequest.create().apply {
interval = 10000
fastestInterval = 5000
priority = LocationRequest.PRIORITY_HIGH_ACCURACY
}
}
}
class LocationLiveData(context: Context) : LiveData<LocationModel>() {
private fun setLocationData(location: Location) {
value = LocationModel(
longitude = location.longitude,
latitude = location.latitude
)
}
}
@mayowa-egbewunmi
mayowa-egbewunmi / LocationModel.kt
Last active September 4, 2019 20:31
LocationModel
data class LocationModel(
val longitude: Double,
val latitude: Double
)
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
class LocationLiveData(context: Context) : LiveData<LocationModel>() {
private var fusedLocationClient = LocationServices.getFusedLocationProviderClient(context)
override fun onInactive() {
super.onInactive()
}
override fun onActive() {
super.onActive()
@mayowa-egbewunmi
mayowa-egbewunmi / LocationActivity.kt
Last active September 4, 2019 20:07
LocationActivity.kt
class LocationActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_location)
}
}
@mayowa-egbewunmi
mayowa-egbewunmi / activity_location.xml
Last active September 4, 2019 20:02
activity_location.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".LocationActivity">
<TextView
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation "android.arch.lifecycle:extensions:1.1.1"