I am developing an Android application (using Kotlin) that needs to access the user's location every 2-3 seconds. I've been researching (and testing) in the past few days for solutions, but I only seem to find examples in Java (that can't easily be translated to Kotlin). I wasn't able to understand it from Android's tutorials either.
What I have already done:
- Asked for permissions (foreground & background GPS position access)
- Made sure they've been accepted before trying to use it
- Implemented the
onLocationChanged()
method - Accessed the last location (and used it)
I would like to update the location so that, by accessing the last location, I can use the newest location that Android knows.
This is something that I've tried, which I thought might be closer to the actual solution (but that is definitely wrong):
val locationListener: LocationListener = this
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 5000, 10, locationListener
)
What is the correct way to do this? Thank you.