请求位置更新的频率超过 5 秒(Android Fused 位置)

2024-01-10

我正在制作一个实时位置监听应用程序,我需要调用位置更新每 3 秒一次。

I use Fused https://developer.android.com/google/play-services/location.html地点。

我的间隔设置为 3 秒,但看起来该间隔的最小值是5秒。

Code:

public class GpsService extends Service implements ConnectionCallbacks, OnConnectionFailedListener, LocationListener {

private static int UPDATE_INTERVAL = 1000 * 3; // /< location update interval
private static int FASTEST_INTERVAL = 1000 * 3; // /< fastest location update interval
private static int DISPLACE_METERS = 10; // displacement in meters, not used atm
private LocationRequest mLocationRequest;
private LocationWrapper mLastLocation;

...


mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(UPDATE_INTERVAL);
mLocationRequest.setFastestInterval(FASTEST_INTERVAL);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

...

@Override
public void onLocationChanged(Location location) {

    mLastLocation = new LocationWrapper(location);
    log("onLocationChanged" + " " + mLastLocation.toString());

}

Logcat:

03-11 14:35:41.559: I/Locationing_GpsService(7410): Lat: 47.513878
03-11 14:35:41.559: I/Locationing_GpsService(7410): Lng: 19.0362011
03-11 14:35:41.559: I/Locationing_GpsService(7410): Accuracy: 21.213 meters
03-11 14:35:41.559: I/Locationing_GpsService(7410): ===================
03-11 14:35:46.554: I/Locationing_GpsService(7410): Lat: 47.5138783
03-11 14:35:46.554: I/Locationing_GpsService(7410): Lng: 19.0362064
03-11 14:35:46.554: I/Locationing_GpsService(7410): Accuracy: 17.32 meters
03-11 14:35:46.554: I/Locationing_GpsService(7410): ===================
03-11 14:35:51.569: I/Locationing_GpsService(7410): Lat: 47.5138752
03-11 14:35:51.569: I/Locationing_GpsService(7410): Lng: 19.0362068
03-11 14:35:51.569: I/Locationing_GpsService(7410): Accuracy: 15.0 meters

您可以看到logcat的日期,延迟5秒后:41, 46, 51我已经阅读了谷歌关于融合位置的文档,但我没有找到任何关于间隔最小值的信息。

有什么建议么?

E D I T:

Added getTime()记录,并将其解析为Date对象,你可以看到5秒延迟更清楚。

03-11 15:16:01.851: I/Locationing_GpsService(16747): Lat: 47.5138798
03-11 15:16:01.851: I/Locationing_GpsService(16747): Lng: 19.0362125
03-11 15:16:01.851: I/Locationing_GpsService(16747): Accuracy: 28.713 meters
03-11 15:16:01.851: I/Locationing_GpsService(16747): Time: Wed Mar 11 15:16:01 CET 2015   
03-11 15:16:01.851: I/Locationing_GpsService(16747): =========================================================
03-11 15:16:06.946: I/Locationing_GpsService(16747): Lat: 47.5138765
03-11 15:16:06.946: I/Locationing_GpsService(16747): Lng: 19.0361987
03-11 15:16:06.946: I/Locationing_GpsService(16747): Accuracy: 20.902 meters
03-11 15:16:06.946: I/Locationing_GpsService(16747): Time: Wed Mar 11 15:16:06 CET 2015   
03-11 15:16:06.946: I/Locationing_GpsService(16747): =========================================================
03-11 15:16:11.971: I/Locationing_GpsService(16747): Lat: 47.5138767
03-11 15:16:11.971: I/Locationing_GpsService(16747): Lng: 19.0361916
03-11 15:16:11.971: I/Locationing_GpsService(16747): Accuracy: 17.326 meters
03-11 15:16:11.971: I/Locationing_GpsService(16747): Time: Wed Mar 11 15:16:11 CET 2015   
03-11 15:16:11.971: I/Locationing_GpsService(16747): =========================================================

编辑2:

权限:

 <uses-permission android:name="android.permission.INTERNET" />
 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

在活动中运行代码并将间隔设置为 0,在 Nexus 4、5 和 7 上每秒生成 1 次更新...就像使用 LocationManager 一样。您可能会受到设备硬件的限制。您是否刚刚尝试使用 LocationRequest 和 LocationManager 请求最快的更新间隔?如果它们都被限制为 5 秒,我会怀疑这是硬件特定于设备的问题。

地点要求:

    mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(0);
    mLocationRequest.setFastestInterval(0);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

Logcat:

03-11 09:50:26.931: D/MainActivity(5623): onLocationChanged Location[fused 0,0 acc=12 et=+1d17h57m7s979ms alt=1505.0 vel=0.0]
03-11 09:50:27.514: D/MainActivity(5623): onLocationChanged Location[fused 0,0, acc=12 et=+1d17h57m8s571ms alt=1505.0 vel=0.0]

Edit: The Docs https://developer.android.com/reference/com/google/android/gms/location/LocationRequest.html#setInterval(long)还告诉您 setInterval(long) 可以以指定的更慢或更快的速率进行更新。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

请求位置更新的频率超过 5 秒(Android Fused 位置) 的相关文章

  • 如何做Android - 滑动抽屉从左到右滑动..?

    如何将android滑动抽屉从LTR滑动 使用时android orientation horizontal 它从 RTL 滑出 我该如何进行 LTR 谢谢 我找到了答案表格 Here http blog sephiroth it 2011
  • java.lang.IllegalArgumentException:此组件要求您指定有效的 android:textAppearance 属性

    我的布局文件之一中有一个 com google android material button MaterialButton 组件 当我使用最新版本的 Material Components 库 com google android mat
  • 如何从 SDK 实现每个会话的 Google Places 自动完成功能?

    是否可以从 Android 和 iOS 应用程序的 place sdk 实现基于会话的自动完成 根据 6 月 11 日生效的新 Google 地图框架定价 对自动完成的请求可以分为基于击键 会话的请求 我找不到描述实施步骤的文档 除了这个参
  • Android 中多个蓝牙连接的自定义 UUID

    我有一个 Android 设备作为服务器连接到多个蓝牙 Android 客户端 我了解 UUID 的概念以及它的独特之处 我的问题是 我可以为连接到我的服务器的所有客户端使用相同的 UUID 吗 如果没有 我如何以编程方式为我的客户端生成
  • 我在布局上看不到任何 FirebaseRecyclerAdapter 项目

    我试图将数据从 Firebase 数据库检索到我的布局 但我看不到任何项目FirebaseRecyclerAdapter在布局中 请帮忙 我按照一个教程展示了如何做到这一点 当我运行应用程序时 我没有看到任何项目 但我可以滚动 public
  • 如何在android中显示保存在sdcard文件夹中的图像[关闭]

    这个问题不太可能对任何未来的访客有帮助 它只与一个较小的地理区域 一个特定的时间点或一个非常狭窄的情况相关 通常不适用于全世界的互联网受众 为了帮助使这个问题更广泛地适用 访问帮助中心 help reopen questions 当我正在显
  • fetchUuidsWithSdp 的奇怪 UUID 逆转

    我有一个在树莓派上运行的 python 蓝牙服务器 使用 PyBluez 我在服务器中使用的uuid是 8f86d132 4ab8 4c15 b8df 0b70cf10ea56 我正在打电话device fetchUuidsWithSdp
  • 在 android 中建立与 MySQL 的池连接

    我需要从我的 Android 应用程序访问 MySQL 数据库 现在所有的工作都通过 DriverManager getConnection url 等等 但我必须从多个线程访问数据库 所以我必须使用连接池 问题1 是 com mysql
  • 当 OnFocusChangeListener 应用于包装的 EditText 时,TextInputLayout 没有动画

    不能比标题说得更清楚了 我有一个由文本输入布局包裹的 EditText 我试图在 EditText 失去焦点时触发一个事件 但是 一旦应用了事件侦听器 TextInputLayout 就不再对文本进行动画处理 它只是位于 editText
  • 图像作为电子邮件附件

    我想构建一个应用程序 我可以在电子邮件中附加图像 打开图像并将其设置为我的壁纸 我想让它跨平台 所以你能告诉我是否可以使用phonegap 或者我是否必须为iphone和android构建一个本机应用程序 您好 如果您只想通过电子邮件附加图
  • 如何在谷歌地图android上显示多个标记

    我想在谷歌地图android上显示带有多个标记的位置 问题是当我运行我的应用程序时 它只显示一个位置 标记 这是我的代码 public class koordinatTask extends AsyncTask
  • logcat 中 mSecurityInputMethodService 为 null

    我写了一点android应显示智能手机当前位置 最后已知位置 的应用程序 尽管我复制了示例代码 并尝试了其他几种解决方案 但似乎每次都有相同的错误 我的应用程序由一个按钮组成 按下按钮应该log经度和纬度 但仅对数 mSecurityInp
  • 使用 AsyncTask 传递值

    我一直在努力解决这个问题 但我已经到了不知道该怎么办的地步 我想做的是使用一个类下载文件并将其解析为字符串 然后将该字符串发送到另一个类来解析 JSON 内容 所有部件都可以单独工作 并且我已经单独测试了所有部件 我只是不知道如何将值发送到
  • WorkManager 或 AlarmManager 用于日常请求然后通知工作?

    这是用例 用户设置具有特定时间的每日通知 在指定时间 发出网络请求以获取一些数据 然后使用检索到的数据显示通知 我不确定是否应该使用 AlarmManager 还是 WorkManager 来实现这个用例 据我了解 AlarmManager
  • 如何在 Android 中从 WorkManager 取消工作?

    我已经保存了 WorkManagerUUID转换成String在领域数据库中 这是代码 Constraints constraints new Constraints Builder setRequiredNetworkType Netwo
  • Android:无法使用 DbHelper 和 Contract 类将数据插入 SQLite

    public class Main2Activity extends AppCompatActivity private EditText editText1 editText2 editText3 editText4 private Bu
  • 如何检查 Android 中的同步设置

    我正在构建一个 Android 应用程序 我需要检查设备中注册的每个单独帐户的同步设置 我知道我可以通过 ContentResolver 类来做到这一点 但我遇到了一些问题 我已设法获取设备上所有帐户的列表 但我不知道在运行时从哪里获取特定
  • 错误:(23, 13) 无法解决:com.google.android.gms:play-services:11.2.0“安装存储库和同步项目”不起作用

    我正在尝试在我的 Android 应用程序中获取位置并更新到服务器 这是我的 Gradle 代码 我在这里包含了compile com google android gms play services 11 2 0 这条线是从文档中 htt
  • 发布的 Android apk 出现错误“包文件未正确签名”

    我最近将我的应用程序上传到 Android 市场 但是由于错误 下载时它拒绝运行 包文件未正确签名 我首先使用 eclipse 发布了数据包 右键单击导出 创建密钥库然后发布 但它拒绝工作 然后我下载了 keytool 和 jarsigne
  • Git 实验分支还是单独的实验存储库?

    我正在开发一个 Android 应用程序 并且在整个开发周期中一直使用 Git 现在 我想构建并发布实验性功能 供人们尝试和安装 同时仍将原始的 稳定的应用程序安装在他们的设备上 现在 这意味着我需要使用不同的包名称 这会更改开发项目中的一

随机推荐