LocationRequest在谷歌Play服务不更新区间设定为小于1秒。 [英] LocationRequest in Google Play Services isn't updating for interval set as less than 1 second.

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

问题描述

我开发一个Android应用程序中,我需要显示每秒30-40更新位置更新。
我使用谷歌的位置API播放服务,在谷歌推出I / O 2013它采用了一体化位置提供商(利用加速度计和GPS与其他沿线的传感器),以便更准确地&安培;高效的定位跟踪。

下面是我的code:

 保护无效startLocationTracking(){
    如果(GooglePlayServicesUtil.isGooglePlayServicesAvailable(本)){
        mLocationClient =新LocationClient(这一点,mConnectionCallbacks,mConnectionFailedListener);
        mLocationClient.connect();
    }
}私人ConnectionCallbacks mConnectionCallbacks =新ConnectionCallbacks(){    @覆盖
    公共无效onDisconnected(){
    }    @覆盖
    公共无效onConnected(捆绑为arg0){
        LocationRequest locationRequest = LocationRequest.create();
        locationRequest.setFastestInterval(0);
        locationRequest.setInterval(0).setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
        mLocationClient.requestLocationUpdates(locationRequest,mLocationListener);
    }
};私人OnConnectionFailedListener mConnectionFailedListener =新OnConnectionFailedListener(){    @覆盖
    公共无效onConnectionFailed(ConnectionResult为arg0){
        Log.e(TAG,为connectionFailed);
    }
};私人LocationListener的mLocationListener =新LocationListener的(){    私人长期mLastEventTime = 0;    @覆盖
        公共无效onLocationChanged(地点){
            双delayBtnEvents =(System.nanoTime() - mLastEventTime)/(1000000000.0);
            mLastEventTime = System.nanoTime();            //采样率是在该更新被接收的频率
            串samplingRate =(新的DecimalFormat(0.0000)格式(1 / delayBtnEvents));            浮速度=(浮点)(location.getSpeed​​()* 3.6); //转换米/秒至公里/小时
            tv.setText(速度+KMPH+,+ samplingRate +赫兹); //更新UI
    }
};

我已经设置优先级PRIORITY_HIGH_ACCURACY和间隔&放大器;最快的时间间隔为0这里毫秒。但我仍然收到只有每1秒更新。


  

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


我已经尝试了区间其他值,但不到1秒的时间间隔不能得到更新。也可用于在清单许可ACCESS_FINE_LOCATION。

我失去了一些东西在这里?是他们的任何其他的方法来做到这一点?我会感激任何帮助解决这个问题。


解决方案

目前你不能得到更新超过每秒一次更快。这是硬件GPS极限。网络位置是一个有点慢(使用时室内) - 目前大约每隔5秒。原始加速度计数据排在一个更高的频率,但往往当直接集成到非常嘈杂。这可能会在今后改进,但可能不会在高频下,你要寻找的。

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.

Here's my code:

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
    }
};

I have set priority as PRIORITY_HIGH_ACCURACY and the interval & the fastest interval as 0 milliseconds here. But I still receive updates on every 1 second only.

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.

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.

解决方案

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.

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

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