Nathan O'Kane Nathan O'Kane - 2 months ago 6
Android Question

Fused Location Provider not updating fast enough

A while ago I wrote a Unity program which logged GPS coordinates and it got a new location about 3 times a second while driving. I'm rewritting the app in Android Studio and using the fused location provider API. It is very slow and only getting GPS coordinates ever 5-15 seconds while driving. Here are some snips of my code which I believe influence the speed of getting a location.

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
...
locationRequest = new LocationRequest();
locationRequest.setInterval(10);
locationRequest.setFastestInterval(15*1000);
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
...
@Override
public void onLocationChanged(Location location) {
myLatitude = location.getLatitude();
mylongitude = location.getLongitude();
....


In order for this app to be viable it needs to log GPS coordinates at least a few times per second. Should I go back to the android.location method for location even though it is advised against?

How do I speed up receiving GPS coordinates?

Answer

You are passing here here interval 10 seconds and fastest interval 15 seconds.You just pass minimum seconds.

And fastest means pass the at least half of your Normal time Interval. Try this way and let me know if you get any problem.

Just remove it and pass here like this.

public final long UPDATE_INTERVAL_IN_MILLISECONDS = 2000;
public final long UPDATE_FASTEST_INTERVAL_IN_MILLISECONDS = UPDATE_INTERVAL_IN_MILLISECONDS / 2;

locationRequest = new LocationRequest();
locationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS );
locationRequest.setFastestInterval(UPDATE_FASTEST_INTERVAL_IN_MILLISECONDS );
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

I have already answered here please check for more info.

Thanks hope this will help you.

Comments