Skip to content

Instantly share code, notes, and snippets.

@mizutori
Created January 6, 2019 13:16
Show Gist options
  • Save mizutori/77ed33d9f28f2c686da04cc209e69a4a to your computer and use it in GitHub Desktop.
Save mizutori/77ed33d9f28f2c686da04cc209e69a4a to your computer and use it in GitHub Desktop.
@SuppressLint("NewApi")
private fun getLocationAge(newLocation: Location): Long {
val locationAge: Long
if (android.os.Build.VERSION.SDK_INT >= 17) {
val currentTimeInMilli = SystemClock.elapsedRealtimeNanos() / 1000000
val locationTimeInMilli = newLocation.elapsedRealtimeNanos / 1000000
locationAge = currentTimeInMilli - locationTimeInMilli
} else {
locationAge = System.currentTimeMillis() - newLocation.time
}
return locationAge
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment