Google Play 服务中的 LocationRequest 不会在设置为小于 1 秒的间隔内更新. [英] LocationRequest in Google Play Services isn't updating for interval set as less than 1 second.

查看:40
本文介绍了Google Play 服务中的 LocationRequest 不会在设置为小于 1 秒的间隔内更新.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 android 应用程序,我需要在其中以每秒 30-40 次更新的速度显示位置更新.我正在使用 Google 中引入的 Google Play 服务的位置 APII/O 2013.它使用融合位置提供程序(利用加速度计和其他传感器以及 GPS)以获得更准确和更准确的定位.高效的位置跟踪.

I'm developing an android app in which I need to show location updates with some 30-40 updates per second. I'm using the Location APIs of Google Play Services, introduced in Google I/O 2013. It uses a fused location provider (making use of accelerometers and other sensors along with GPS) for more accurate & efficient location tracking.

这是我的代码:

protected void startLocationTracking() {
    if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(this)) {
        mLocationClient = new LocationClient(this, mConnectionCallbacks, mConnectionFailedListener);
        mLocationClient.connect();
    }
}

private ConnectionCallbacks mConnectionCallbacks = new ConnectionCallbacks() {

    @Override
    public void onDisconnected() {
    }

    @Override
    public void onConnected(Bundle arg0) {
        LocationRequest locationRequest = LocationRequest.create();
        locationRequest.setFastestInterval(0);
        locationRequest.setInterval(0).setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
        mLocationClient.requestLocationUpdates(locationRequest, mLocationListener);
    }
};

private OnConnectionFailedListener mConnectionFailedListener = new OnConnectionFailedListener() {

    @Override
    public void onConnectionFailed(ConnectionResult arg0) {
        Log.e(TAG, "ConnectionFailed");
    }
};

private LocationListener mLocationListener = new LocationListener() {

    private long mLastEventTime = 0;

    @Override
        public void onLocationChanged(Location location) {
            double delayBtnEvents = (System.nanoTime()- mLastEventTime )/(1000000000.0);
            mLastEventTime = System.nanoTime();

            //Sampling rate is the frequency at which updates are received
            String samplingRate = (new DecimalFormat("0.0000").format(1/delayBtnEvents));     

            float speed = (float) (location.getSpeed() * 3.6);  // Converting m/s to Km/hr
            tv.setText(speed + " kmph" + ", " + samplingRate + " Hz"); //Updating UI
    }
};

我已将优先级设置为 PRIORITY_HIGH_ACCURACY 和间隔 &此处最快的间隔为 0 毫秒.但我仍然每 1 秒收到一次更新.

这很像 GPS 传感器的更新频率任何安卓手机.但我期待更多,因为这是使用 Fusion传感器(包括加速度计).加速度计的一部分融合传感器应该产生比这更高的频率.

This pretty much looks like the update frequency of the GPS sensor of any Android phone. But I was expecting more as this is using a Fusion Sensor (which includes accelerometer). Accelerometer being part of fusion sensor should yield higher frequency than this.

我尝试了其他的间隔值,但无法在少于 1 秒的间隔内获得更新.ACCESS_FINE_LOCATION 也用于清单中的权限.

I have tried other values for the interval, but could not get updates for less than 1 sec interval. Also ACCESS_FINE_LOCATION is used for permission in manifest.

我在这里遗漏了什么吗?他们还有其他方法可以做到这一点吗?如果您能帮助我解决此问题,我将不胜感激.

Am I missing something here? Is their any other approach to accomplish this? I'll be grateful for any help to solve this.

推荐答案

目前,您无法以每秒一次的速度获得更新.这是硬件 GPS 限制.网络位置有点慢(在室内使用) - 目前大约每 5 秒一次.原始加速度计数据以更高的频率进入,但直接集成时往往会非常嘈杂.这在未来可能会有所改善,但可能不会达到您想要的高频.

Currently you can't get updates faster than once per second. This is the hardware gps limit. Network location is a bit slower (used when indoors) - currently about once every 5 seconds. Raw accelerometer data comes in at a higher frequency, but tends to be very noisy when integrated directly. This may improve in the future, but probably not at the high frequency you're looking for.

这篇关于Google Play 服务中的 LocationRequest 不会在设置为小于 1 秒的间隔内更新.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆