Skip to content

Commit

Permalink
accuracy added
Browse files Browse the repository at this point in the history
  • Loading branch information
nawinkhatiwada committed Aug 30, 2021
1 parent 812e2c1 commit 8494456
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class LocationActivity : BaseActivity() {
override fun onLocationChanged(location: Location?) {
this.location = location
Log.d("Location fetched:", "${this.location?.latitude}, ${this.location?.longitude}")
binding.tvCurrentLocation?.text =
"Latitude: ${this.location?.latitude}\nLongitude: ${this.location?.longitude}"
binding.tvCurrentLocation?.text = """Latitude: ${this.location?.latitude}\n
Longitude: ${this.location?.longitude}\n
Accuracy: ${this.location?.accuracy}"""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package com.androidbolts.library
class LocationModel(
var timeInMills: Long,
var latitude: Double,
var longitude: Double
var longitude: Double,
var accuracy: Float
)
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,17 @@ internal class GpsManager internal constructor() : GpsProvider() {
mLocationCallback = object : LocationCallback() {
override fun onLocationResult(locationResult: LocationResult?) {
super.onLocationResult(locationResult)
mCurrentLocation = locationResult?.lastLocation
mCurrentLocation = if (locationResult?.locations.isNullOrEmpty()) {
locationResult?.lastLocation
} else {
locationResult?.locations?.first()
}
mCurrentLocation?.let { currentLocation ->
val locationModel = LocationModel(
System.currentTimeMillis(),
currentLocation.latitude,
currentLocation.longitude
currentLocation.longitude,
currentLocation.accuracy
)
getPrefs()?.setLocationModel(locationModel)
}
Expand Down

0 comments on commit 8494456

Please sign in to comment.