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.