【问题标题】:GeofencingClient take lot of time in adding the geofencesGeofencingClient 需要花费大量时间来添加地理围栏
【发布时间】:2019-05-30 09:01:53
【问题描述】:

我有一个依赖于地理围栏技术的功能有一个奇怪的问题。添加地理围栏时,客户端需要花费大量时间来添加(查看日志)。这很奇怪,因为它在早期工作得很好(没有与位置相关的代码更改和所有 afaik),没有任何延迟。

我正在使用以下依赖项:

'com.google.android.gms:play-services-location:16.0.0'

@RequiresPermission(Manifest.permission.ACCESS_FINE_LOCATION)
    fun addGeoFences(
            geoFences: ArrayList<Geofence>,
            onSuccess: () -> Unit = {},
            onFailure: (Exception) -> Unit = {}
    ): Boolean {
        if (isAddingGeofence) {
            GlobalLoggerUtils.showLog(TAG, "isAddingGeofence: $isAddingGeofence")
            return false
        }
        GlobalLoggerUtils.showLog(TAG, "addGeoFences()")

        if (geoFences.size == 0) {
            return false
        }
        isAddingGeofence = true

        geoFencingClient
                .addGeofences(
                        getGeoFencingRequest(geoFences),
                        geoFencePendingIntent
                ).addOnSuccessListener { result ->
                    isAddingGeofence = false
                }
                .addOnFailureListener { exception ->
                    isAddingGeofence = false
                }
                .addOnCanceledListener {
                    isAddingGeofence = false
                }
        return true
    }



2019-05-30 12:43:29.716  I/: addGeoFences() 
2019-05-30 12:44:00.602  I/: isAddingGeofence: true 
2019-05-30 12:44:02.424  I/: isAddingGeofence: true 
2019-05-30 12:44:03.525  I/: isAddingGeofence: true 
2019-05-30 12:44:04.975  I/: isAddingGeofence: true 
2019-05-30 12:44:06.541  I/: isAddingGeofence: true 
2019-05-30 12:48:18.384  I/: add success >>> result: null  
2019-05-30 12:48:18.393  I/: add success >>> requestIds: XYZ  

让我知道是否需要在此问题的上下文中添加任何内容。根据official Android documentation 添加地理围栏。

编辑 #1:2019 年 6 月 5 日

看起来这种情况只发生在开发版本中。工作正常 从 Play 商店安装的发布版本。

【问题讨论】:

    标签: android kotlin google-play-services android-geofence


    【解决方案1】:

    如果是 Android 8.0+,请注意后台位置限制也适用于地理围栏 APIenter link description here

    【讨论】:

    • 感谢 Loius 的回答。但我知道这一点,并不是所要求的。我在添加地理围栏不等待事件时遇到了长时间延迟/等待时间的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-17
    • 1970-01-01
    • 2018-12-28
    • 2016-06-21
    • 1970-01-01
    • 2015-06-22
    相关资源
    最近更新 更多