LocationRequest in Google Play Services isn't updating for interval set as less than 1 second.

10,602

Solution 1

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.

Solution 2

I am trying to change with below parameter and its working for me with whatever I set.

locationRequest.setFastestInterval(10000); // Every 10 sec it gives lat/lng

Please try with in your side with same change.

Share:
10,602
Vinayak
Author by

Vinayak

Senior Mobile Dev, Tech Enthusiast, Avid Reader, Love Video Games

Updated on June 04, 2022

Comments

  • Vinayak
    Vinayak almost 2 years

    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.

  • Vinayak
    Vinayak almost 11 years
    The setInterval() method takes only long values, so I can't pass float/double values here.
  • Vinayak
    Vinayak almost 11 years
    As per the documentation, it says that "Applications cannot specify the exact location sources, such as GPS, that are used by the LocationClient. In fact, the system may have multiple location sources (providers) running and may fuse the results from several sources into a single Location object." Other options are PRIORITY_BALANCED_POWER_ACCURACY and PRIORITY_NO_POWER. In the former case it has 100 meter accuracy (which is too much for my use) and latter makes the app passive listener to locations accessed by other apps.I'm stuck with PRIORITY_HIGH_ACCURACY.
  • Vinayak
    Vinayak over 10 years
    Did you try setting it less than 1 second?
  • PrashantAdesara
    PrashantAdesara over 10 years
    You can set less than 1 second. I must have to say that Hardware GPS chipsets have its limitation so it may not be giving data if we set less than 1sec.