0

I have an application with xamarin essentials. This takes the information every 5 seconds with a waiting time of 3 seconds of GPS

 Device.StartTimer(TimeSpan.FromMilliseconds(Timmer), () => { RunPoint(); return isRunningTimer; });

    public async void RunPoint()
    {       try
            {
                DateTime dateLanch = DateTime.Now;
                var request = new GeolocationRequest(accuracy, TimeSpan.FromSeconds(TimeOutGps));
                var location = await Geolocation.GetLocationAsync(request);

                if (location != null)
                {
                    point = new GPSPoint
                    {
                        Status = StatusGPS.OK,
                        Point = new Cerezasoft.Geo.Points.Point { Latitude = location.Latitude, Longitude = location.Longitude },
                        Stamp = location.Timestamp.LocalDateTime,
                        StampSystem = DateTime.Now,
                        StampLanch = dateLanch,
                        StampUniversal = location.Timestamp.UtcDateTime,
                        Speed = 0,
                        SpeedGPS = location.Speed.HasValue ? location.Speed.Value : 0,
                        Elevation = location.Altitude.HasValue ? location.Altitude.Value : 0
                    };
                }
                else
                {
                    point.Status = StatusGPS.ErrorCalculo;
                }
            }
            catch (FeatureNotSupportedException fnsEx)
            {
                point.Status = StatusGPSRallySystem.NoSensor;
                point.MessageError = fnsEx.Message;
            }
            catch (PermissionException pEx)
            {
                point.Status = StatusGPS.NoAcces;
                point.MessageError = pEx.Message;
            }
            catch (Exception ex)
            {
                point.Status = StatusGPS.ErrorSensor;
                point.MessageError = ex.Message;
            }
}

when application use with another application with gps. The capture of gps information works very well but if you execute the precision and the quality of the data, the location becomes erratic.

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location" android:required="false" />
<uses-feature android:name="android.hardware.location.gps" android:required="true" />
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
        Xamarin.Essentials.Platform.Init(this, savedInstanceState);
    }

I do a comparison with another app in split screen and it works fine. when my app works alone, the operating system returns the position in a different way. when my app runs by itself. the operating system returns the position more erratically.both tests are carried out in the same place with the same conditions and the same cell phone. I do not know what services and what additional elements are activating the other app for the optimal functioning of the gps

Thanks for the collaboration

Barney CBZ
  • 101
  • 7
  • *"if you execute the precision and the quality of the data, the location becomes erratic"* - I don't understand that sentence. Which lines of code result in an erratic location? And what do you mean by "erratic" - how are you testing? Are you on an actual device, outdoors, with good satellite signals (away from buildings, trees)? Which device? Show an actual sequence of values that you get - its possible what you consider "erratic" is "normal behavior" for gps. Cell phones have limited antenna length, and must balance accuracy with battery consumption. They are not precision gps devices. – ToolmakerSteve Oct 28 '21 at 03:24
  • 1
    Personally, I take frequent quick gps measurements, and apply my own filtering to them. Googling, see [this SO thread](https://stackoverflow.com/q/5257812/199364) and [here is one good discussion](https://maddevs.io/insights/blog/reduce-gps-data-error-on-android-with-kalman-filter-and-accelerometer/). – ToolmakerSteve Oct 28 '21 at 03:25
  • When you make an async call to Geolocation it takes some time to poll the sensor to get a value based on the parameters you set. Given the relatively short window you are giving the system to give you a value I'm surprised it seems "erratic". If you really need the values that fast you may be better implementing this is a platform specific manner and subscribing to location updates on each platform. Then you can buffer them yourself and pass something less erratic back to Xamarin Forms. – CodingLumis Oct 28 '21 at 10:27
  • I do a comparison with another app in split screen and it works fine. when my app works alone, the operating system returns the position in a different way. when my app runs by itself. the operating system returns the position more erratically.both tests are carried out in the same place with the same conditions and the same cell phone. I do not know what services and what additional elements are activating the other app for the optimal functioning of the gps – Barney CBZ Oct 28 '21 at 18:46
  • *"I do not know what services and what additional elements are activating the other app for the optimal functioning of the gps"* I presume the other app has done some custom "filtering", their own code, to get a more stable result. There is no "simple" answer anyone can tell you, AFAIK. Hence my links above. – ToolmakerSteve Oct 29 '21 at 01:06
  • " I presume the other app has done some custom "filtering", their own code, to get a more stable result" the problem is that when both applications work the same; Both apps work in isolation because that's how Android works. operating system controls gps data. I don't know what I'm missing I only worked this out james montemagno :0 – Barney CBZ Oct 29 '21 at 02:37

2 Answers2

1

"I do a comparison with another app in split screen and it works fine. when my app works alone, the operating system returns the position in a different way. when my app runs by itself. the operating system returns the position more erratically."

I am running into the exact same issue as explained above

This is my code

locator = CrossGeolocator.Current;
if (locator.IsGeolocationAvailable && locator.IsGeolocationEnabled)
{
    locator.DesiredAccuracy = 10;
    await locator.StartListeningAsync(TimeSpan.FromSeconds(15), 10, false, new Plugin.Geolocator.Abstractions.ListenerSettings()
    {
        AllowBackgroundUpdates = true,
        ActivityType = Plugin.Geolocator.Abstractions.ActivityType.Fitness,
        PauseLocationUpdatesAutomatically = false
    });
    locator.PositionChanged += Postion_Changed;
}

public void Postion_Changed(object sender, Plugin.Geolocator.Abstractions.PositionEventArgs e)
{
    if (e.Position.Accuracy < 75)
    {
       LocationService.SaveGpsLocation(e.Position.Latitude, e.Position.Longitude, e.Position.Timestamp.DateTime);
    }
}

When running it with another GPS app it's pinpoint accurate, but when running alone it jumps around A LOT.

"I presume the other app has done some custom "filtering", their own code, to get a more stable result. There is no "simple" answer anyone can tell you, AFAIK. Hence my links above."

This cannot be true, because that would not affect our apps at all. They are simply managing to request a much finer location which in turn helps our app somehow - we are just trying to figure out why.

  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/30798986) – Vapid Jan 18 '22 at 14:31
  • Your app is "Piggybacking" on the other app, see [Passive Provider](https://learn.microsoft.com/en-us/xamarin/android/platform/maps-and-location/location#location-fundamentals) – TouchBoarder Aug 31 '23 at 11:09
0

I am using the Geolocation functionality of Xamarin Essentials in my app as a background service and I have the same bad coordinates accuracy problem. If I detect the coordinates every 5-10 seconds standing still, most of them are 20-30 meters from the correct position even if the returned accuracy is 6-8 meters. I tried to disable the "Improve Location Accuracy" option with no success. Other apps are much more accurate under the same conditions.

gps58
  • 1