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;
});
}
}