Add check for location accuracy
This commit is contained in:
parent
6fd476f262
commit
cc676a39ac
2 changed files with 8 additions and 5 deletions
|
@ -204,13 +204,14 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis
|
||||||
providers.add(0, providers.removeAt(passiveFirst))
|
providers.add(0, providers.removeAt(passiveFirst))
|
||||||
}
|
}
|
||||||
// find location
|
// find location
|
||||||
|
var location: net.osmand.Location? = null
|
||||||
for (provider in providers) {
|
for (provider in providers) {
|
||||||
val location = convertLocation(service.getLastKnownLocation(provider))
|
val loc = convertLocation(service.getLastKnownLocation(provider))
|
||||||
if (location != null) {
|
if (loc != null && (location == null || loc.hasAccuracy() && loc.accuracy < location.accuracy)) {
|
||||||
return location
|
location = loc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null
|
return location
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupAlarm() {
|
private fun setupAlarm() {
|
||||||
|
|
|
@ -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 MY_LOCATION_UPDATE_MS = 15000 // 15 sec
|
||||||
|
|
||||||
|
private const val UPDATE_LOCATION_ACCURACY = 30 // 30 meters
|
||||||
|
|
||||||
class ShareLocationHelper(private val app: TelegramApplication) {
|
class ShareLocationHelper(private val app: TelegramApplication) {
|
||||||
|
|
||||||
private val log = PlatformUtil.getLog(ShareLocationHelper::class.java)
|
private val log = PlatformUtil.getLog(ShareLocationHelper::class.java)
|
||||||
|
@ -52,7 +54,7 @@ class ShareLocationHelper(private val app: TelegramApplication) {
|
||||||
fun updateLocation(location: Location?) {
|
fun updateLocation(location: Location?) {
|
||||||
lastLocation = location
|
lastLocation = location
|
||||||
|
|
||||||
if (location != null) {
|
if (location != null && location.accuracy < UPDATE_LOCATION_ACCURACY) {
|
||||||
lastLocationUpdateTime = System.currentTimeMillis()
|
lastLocationUpdateTime = System.currentTimeMillis()
|
||||||
if (app.settings.getChatsShareInfo().isNotEmpty()) {
|
if (app.settings.getChatsShareInfo().isNotEmpty()) {
|
||||||
shareLocationMessages(location, app.telegramHelper.getCurrentUserId())
|
shareLocationMessages(location, app.telegramHelper.getCurrentUserId())
|
||||||
|
|
Loading…
Reference in a new issue