Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android GPS update frequency

Tags:

java

android

gps

I'm writing a lap timing app but have run into a GPS update frequency problem. At speeds greater than 75km/h (21m/s) my code stops working. My question is how can I request updates at a faster rate? I need it work at speeds up to 300km/h (83m/s) and would like the app to get updates every couple of meters traveled which would mean it would need an update every 0.025 seconds @ 300km/h. Below is my code, I tried an alternate code to get time stamp but got the same result, I believe it's a GPS update frequency problem not a code problem. I wanted updates every couple of meters @ 300km/h in case the phone passes through the proximity radius on a tangent.

int prox = 30;      // Proximity Switch To Finish Line = 30 meters
int speedGov = 0;   // Speed In Kmh

public void OnProviderDisabled(string provider)
{
}

public void OnProviderEnabled(string provider)
{
}

public void OnStatusChanged(string provider, Availability status, Bundle extras)
{
}

protected override void OnResume()
{
    this.InitializeLocationManager();
    base.OnResume();
    _locationManager.RequestLocationUpdates(_locationProvider, 0, 0, this);
}

void InitializeLocationManager()
{
    _locationManager = (LocationManager)GetSystemService(LocationService);
    Criteria criteriaForLocationService = new Criteria
    {
        Accuracy = Accuracy.Fine
    };
    IList<string> acceptableLocationProviders =     _locationManager.GetProviders(criteriaForLocationService, true);
    if (acceptableLocationProviders.Any())
    {
        _locationProvider = acceptableLocationProviders.First();
    }
    else
    {
        _locationProvider = String.Empty;
    }
}

public void OnLocationChanged(Location location)
{
    _currentLocation = location;
    if (_currentLocation == null)
    {
    }
    else
    {
        d2fl = Convert.ToInt32(_currentLocation.DistanceTo(fl));
        speedGov = Convert.ToInt32(_currentLocation.Speed * 3.6);
    }
}

int A = 0;      // 1st Distance to Finish Line
int B = 1000000;    // 2nd Distance to Finish Line

// Get Time Stamp
while (true)
{
    A = d2fl;
    if (A > B && d2fl < prox && speedGov > 2)   // Travelling away from Finish Line & Within 30m proximity to Finish Line & Going faster than 2km/h
    {
        // Time stamp for when phone first starts travelling away from Finish Line
        string hours = DateTime.Now.ToString("HH");
        string minutes = DateTime.Now.ToString("mm");
        string seconds = DateTime.Now.ToString("ss");
        string milliseconds = DateTime.Now.ToString("fff");
        lapFinishTimeStamp = (Convert.ToDecimal(hours) * 3600) + (Convert.ToDecimal(minutes) * 60) + Convert.ToDecimal(seconds) + (Convert.ToDecimal(milliseconds) / 1000);
        A = 0;
        B = 1000000;
        break;
    }
    B = A;
}

// Alternate Get Time Stamp - worked the same as above "Get Time Stamp"
while (true)
{
    int A = d2fl;
    Thread.Sleep(5);
    int B = d2fl;
    if (A < B && d2fl < prox && speedGov > 2)
    {
        string hours = DateTime.Now.ToString("HH");
        string minutes = DateTime.Now.ToString("mm");
        string seconds = DateTime.Now.ToString("ss");
        string milliseconds = DateTime.Now.ToString("fff");
        lapFinishTimeStamp = (Convert.ToDecimal(hours) * 3600) +     (Convert.ToDecimal(minutes) * 60) + Convert.ToDecimal(seconds) + (Convert.ToDecimal(milliseconds) / 1000);
        A = 0;
        B = 0;
        break;
        }
    A = 0;
    B = 0;
}

Have read some other anwsers on this forum but are a few years old. This app will need to work on Galaxy S4 onwards.

Plus I'm a little confused about the GPS frequency's, from what I've read the GPS frequency operates at quite a high rate (hardware is around 1.6 GHz) but the phones operating systems seems to cull the data to a lower frequency, is this intentional?

like image 554
Kringle Avatar asked Jul 21 '15 03:07

Kringle


People also ask

How often does gps update Android?

Fused Location Provider API | Google Developers some update every 15 min and some update upon a state change. Location also updates when the sensors update.

What is location update interval?

} The priority of PRIORITY_HIGH_ACCURACY , combined with the ACCESS_FINE_LOCATION permission setting that you've defined in the app manifest, and a fast update interval of 5000 milliseconds (5 seconds), causes the fused location provider to return location updates that are accurate to within a few feet.


1 Answers

Don't confuse the the radio frequency value (1.1-1.6GHz) from how frequently you will get location updates (1Hz).

Have you seen the device list in: Get GPS position on a precise time interval ? Even though its a few years old, I doubt any on device GPS will report any faster (probably due to battery/noise/use case design). Even if the on board device was reporting at 10Hz or 20Hz that is only 100ms or 50ms which is still slower than your requirement of 25ms. Remember if the CPU is talking to the GPS and calculating location - it is eating battery which is the limiting factor on mobile devices.

If you want consistent sub-second GPS value updates you'll need to use an external device.

like image 192
Morrison Chang Avatar answered Oct 01 '22 13:10

Morrison Chang