Add check for location accuracy

This commit is contained in:
Chumva 2019-02-02 13:14:57 +02:00
parent 6fd476f262
commit cc676a39ac
2 changed files with 8 additions and 5 deletions

View file

@ -204,13 +204,14 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis
providers.add(0, providers.removeAt(passiveFirst))
}
// find location
var location: net.osmand.Location? = null
for (provider in providers) {
val location = convertLocation(service.getLastKnownLocation(provider))
if (location != null) {
return location
val loc = convertLocation(service.getLastKnownLocation(provider))
if (loc != null && (location == null || loc.hasAccuracy() && loc.accuracy < location.accuracy)) {
location = loc
}
}
return null
return location
}
private fun setupAlarm() {

View file

@ -15,6 +15,8 @@ private const val USER_SET_LIVE_PERIOD_DELAY_MS = 5000 // 5 sec
private const val MY_LOCATION_UPDATE_MS = 15000 // 15 sec
private const val UPDATE_LOCATION_ACCURACY = 30 // 30 meters
class ShareLocationHelper(private val app: TelegramApplication) {
private val log = PlatformUtil.getLog(ShareLocationHelper::class.java)
@ -52,7 +54,7 @@ class ShareLocationHelper(private val app: TelegramApplication) {
fun updateLocation(location: Location?) {
lastLocation = location
if (location != null) {
if (location != null && location.accuracy < UPDATE_LOCATION_ACCURACY) {
lastLocationUpdateTime = System.currentTimeMillis()
if (app.settings.getChatsShareInfo().isNotEmpty()) {
shareLocationMessages(location, app.telegramHelper.getCurrentUserId())