Android onLocationChanged 最快每秒只调用一次

标签 android location

我正在使用 FusedLocationApi 获取更新。但是尽管将 LocationRequest.setInterval 设置为 500 甚至 200 毫秒,但我每秒只能获得一次更新。如果可能的话,我想每秒两次(做一个移动平均速度)。有硬性限制吗?

在我的 Activity onCreate 中:

googleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .addApi(AppIndex.API).build();

在我的“onConnected”方法中:

this.locationRequest = new LocationRequest();
this.locationRequest.setInterval(200);
this.locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
LocationServices.FusedLocationApi.requestLocationUpdates(this.googleApiClient, this.locationRequest, this);

我还有一个单独的 LocationManager,我只使用它来通过 addGpsStatusListener() 获取状态更改,这些似乎工作正常。

谢谢

最佳答案

根据文档

This interval is inexact. You may not receive updates at all (if no location sources are available), or you may receive them slower than requested.

您可以尝试使用public LocationRequest setFastestInterval (long millis)。文档指出:

he fastest rate that that you will receive updates can be controlled with setFastestInterval(long). By default this fastest rate is 6x the interval frequency.

同时确保您请求 ACCESS_FINE_LOCATION。该文档还指出:

Applications with only the coarse location permission may have their interval silently throttled

关于Android onLocationChanged 最快每秒只调用一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38083372/

相关文章:

ios - Xcode 如何在您的生产应用程序中防止或检测 "Location Simulation"? [大事件]

android - 通过标签在另一个 fragment 中查找子 fragment

java - 景观计算后的android事件

java - 尝试在 EditText 中将数字设置为文本

firefox - Facebook Javascript SDK 窗口位置重新加载在 Firefox 上不起作用

jquery:延迟()+ window.location?

safari - top.location.replace 在 Safari/Chrome 中创建历史记录项

android - 了解 Couchbase lite android 中已删除的文档

Android,如何增加列表适配器中的行高?

android - 如何从我的 Android 应用程序在 Google map 中标记特定位置