java - Android - 一段时间后获取位置

标签 java android gps location

我可以使用 LocationManager 获取 minDistance 和 minTime 的位置。

但是,例如,我如何才能每 15 秒获取一次位置? (即使用户没有移动)

        if (Utils.hasProvider(LocationManager.GPS_PROVIDER)) {
            mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 15000, 100f, this);
        }

        if (Utils.hasProvider(LocationManager.NETWORK_PROVIDER)) {
            mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 15000, 100f, this);
        }

最佳答案

谷歌文档说

The minDistance parameter can also be used to control the frequency of location updates. If it is greater than 0 then the location provider will only send your application an update when the location has changed by at least minDistance meters, AND at least minTime milliseconds have passed. However it is more difficult for location providers to save power using the minDistance parameter, so minTime should be the primary tool to conserving battery life.

因此涉及到一个 AND 条件。因此,您应该将距离参数设置为 0。在这种情况下,您将每 15 秒更新一次位置。

关于java - Android - 一段时间后获取位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33014829/

相关文章:

java - 带有 Android 应用程序的 Golang 后端

java - Android 更好地实现了用于导航的 fragment

ios - ios“智能”位置跟踪器和电池消耗

java - 从连接池中释放连接

java - 服务中的广播接收器未接收 Intent

java - Jboss wildfly Java 兼容性

移动应用程序在后台时的 GPS 位置(使用 ionicframework)

android - 在android中使用纬度和经度值获取位置名称

java - 在虚拟机上运行 selenium grid 的问题

java - 如何在 JSF 中编写 Java 代码?