Wednesday, 11 August 2021

In my android app using Fused Location Client, Why am I getting stale GPS when using this code

My app displays a navigation chart, and if a current GPS position is available, it shows that too. I tested this on a ship moving along a known route. Sometimes the correct position is shown. Sometimes I get an old GPS location, even when asking for a fresh read. At times it seems to get stuck on an old location for several reads. When that happened, I ran Google Maps, it seems to clear the error and I start getting a fresh location again.

// try to look at GPS....
        status1 = checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION);
        if (status1 != PackageManager.PERMISSION_GRANTED)
        {   requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION},10);
        }
        status2 = checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION);
        Object cancellationToken = null;
        if (status2 == PackageManager.PERMISSION_GRANTED)
            fusedLocationClient.getCurrentLocation(PRIORITY_HIGH_ACCURACY, (CancellationToken) cancellationToken)
                    .addOnSuccessListener(this, location -> // using lambda expression...

                    {   if (location != null)
                    {   GPSLatitude = location.getLatitude();
                        GPSLongitude = location.getLongitude();
                        gotGPS = true;
                        //if we have a location, and it is on chart, draw the blue dot....

Google maps is better at reading the GPS than I am. Should I consider another approach.



from In my android app using Fused Location Client, Why am I getting stale GPS when using this code

No comments:

Post a Comment