Hello,
Welcome to our Microsoft Q&A platform!
You can use Xamarin.Essentials: Geolocation or the Geolocator Plugin to achieve this function.
For Xamarin.Essentials: Geolocation, you can query the current device's location coordinates by using method GetLocationAsync
:
CancellationTokenSource cts;
async Task GetCurrentLocation()
{
try
{
var request = new GeolocationRequest(GeolocationAccuracy.Medium, TimeSpan.FromSeconds(10));
cts = new CancellationTokenSource();
var location = await Geolocation.GetLocationAsync(request, cts.Token);
if (location != null)
{
Console.WriteLine($"Latitude: {location.Latitude}, Longitude: {location.Longitude}, Altitude: {location.Altitude}");
}
}
catch (FeatureNotSupportedException fnsEx)
{
// Handle not supported on device exception
}
catch (FeatureNotEnabledException fneEx)
{
// Handle not enabled on device exception
}
catch (PermissionException pEx)
{
// Handle permission exception
}
catch (Exception ex)
{
// Unable to get location
}
}
protected override void OnDisappearing()
{
if (cts != null && !cts.IsCancellationRequested)
cts.Cancel();
base.OnDisappearing();
}
You can save Latitude
and Altitude
coordinate after 10 sec or 20 sec in a form of csv values in text file.
And there are some tutorials about this, you can find these tutorials by enter keywords Finding Your Way with the Xamarin.Essentials Geolocation API
and Xamarin Forms Google Maps Tracking Path
in your browser.
Best Regards,
Jessie Zhang
---
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.