Xamarin Essentials Geolocator - accuracy and response

Has anyone any experience with geolocator - I am beginning to experiment trying to build a simple gps logger.
I seem to get some weird results - at first the code returns a credible location then it just seems to record the same position for 10 mins at a time (despite moving at >20mph
the routine is embedded within a timer which fires every 12 seconds - the timeout on the getposition async call is 6 seconds
Some things I dont quite understand - it seems that in the event of a timeout GetLocationAsync simply returns the last position - it seems so because the time stamp is the same
I just dont get why it is not firing a position update - I tried using a 2 seconds timeout and it did better than 6 second - I've also increased the timer firing to 15 seconds and the timeout on the Geolocator to 10 seconds but doesn't seem to stop the position update from 'freezing' for up to 10 mins
Yes I am aware of the need to have a clear view of the sky
The odd thing is I have an Android app utility GPS status which shows satellites and a fix - once its locked on it updates about every 0.8 seconds - why cant geolocator do that? Is there any inherent reason why the response from the underlying location service should be slower with Xamarin Essentials?
Also I have resurrected an older Xamarin Android sample app which uses the Android location service directly (not Forms) and this seems to update happily and frequently. Is it something to do with Forms?
Anyone know if I could use dependency service and call the Android location services directly ? Or would that be a daft idea? I'd really like to stick with Forms and Essentials - James has always been in the vanguard of making complex things accessible to beginners like me.
I'd welcome any comments on the above conjectures and also - is my code approach the best way of doing it ?

I write all the positions to a gpx file so I can plot them on a map and frankly the results are gobbledegook

code snippet
{
static string gpx ="";

async void OnTimedEventAsync(Object source, System.Timers.ElapsedEventArgs e)
        {
                 request = new GeolocationRequest(GeolocationAccuracy.High,TimeSpan.FromSeconds(6));
                   var x = await Geolocation.GetLocationAsync(request);
                    var acc = x.Accuracy;
                    var dt = x.Timestamp;
                    dt = dt.UtcDateTime;
                    var alt = x.Altitude;                        
                    alt = Math.Round((float)alt * 3.28084, 0); // convert to feet
                    var spd = x.Speed;
                     spd = Math.Round((float)spd * 1.94384, 0); //convert to knots
                    var cse = x.Course;
                    var dt2 = dt.ToString("yyyy-MM-ddTHH:mm:ssZ");

                    gpx = gpx + "<trkpt lat =\"" + x.Latitude.ToString() + "\" lon=\"" + x.Longitude.ToString() + "\">";
                    gpx = gpx + "<time>" + dt2 + "</time>";
                    gpx = gpx + "<course>" + cse.ToString() + "</course>";
                    gpx = gpx + "<speed>" + spd.ToString() + "</speed>";
                    gpx = gpx + "<acc>" + acc.ToString() + "</acc>";
                    gpx = gpx + "</trkpt>";
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        // interact with UI elements to show something happening
                        lab1.Text = gpx;
                    });                    
        }

}

Answers

  • YorkGoYorkGo CNMember, Xamarin Team Xamurai

    Anyone know if I could use dependency service and call the Android location services directly ? Or would that be a daft idea?

    Feel free to use it. Actually, Xamarin.Essentials Geolocator also did it by using dependency service.

  • MicialMicial USMember ✭✭

    I'd really like to stick with Forms and Essentials - James has always been in the vanguard of making complex things accessible to beginners like me.

    You could file a issue report on Github: https://github.com/xamarin/Essentials/issues/new

  • utekaiutekai USMember ✭✭✭
    edited February 13

    new GeolocationRequest(GeolocationAccuracy.High,TimeSpan.FromSeconds(6)); is based upon your network location in a very general sense (within miles).

    You want to tap into what they call satellite data. Of course the finest detail of your location is actually known, your challenge is to be able to weave your way to that info. The 'owners' don't want you to know just how much they already know.

  • utekaiutekai USMember ✭✭✭

    There is also a built in call to retrieve geolocation history, the Geolocator.GetGeoPositionHistoryAsync call.

    In the Geolocator class, there is also a setting Movement threshold that determines how much change is required before the event will fire again.

    But for accuracy, you want satellite data. You might check out the microsoft docs on this issue.

    https://docs.microsoft.com/en-us/uwp/api/windows.devices.geolocation.geocoordinate

  • utekaiutekai USMember ✭✭✭

    And this, and remember I propose your lack of accuracy is due to the geolocation using IP address.

    Note what the ms docs state about it.

    https://docs.microsoft.com/en-us/uwp/api/windows.devices.geolocation

Sign In or Register to comment.