GeolocatorPlugin
GeolocatorPlugin copied to clipboard
Run Geolocator Even App Close (Android, IOS)
Hello Friends,
Sorry for asking that question but i really searched everywhere about solution of this problem. My code is below. I want to run this function as a service. It should run as background even app close for both of android and IOS. Is it possible or not ?
private async void gps_deneme_Clicked(object sender, EventArgs e)
{
try
{
var hasPermission = await Utils.CheckPermissions(Permission.Location);
if (!hasPermission)
return;
gps_deneme.IsEnabled = false;
var locator = CrossGeolocator.Current;
locator.DesiredAccuracy = DesiredAccuracy.Value;
labelGPS.Text = "Getting gps...";
var position = await locator.GetPositionAsync(TimeSpan.FromSeconds(Timeout.Value), null, IncludeHeading.IsToggled);
if (position == null)
{
labelGPS.Text = "null gps :(";
return;
}
labelGPS.Text = string.Format("Time: {0} \nLat: {1} \nLong: {2} \nAltitude: {3} \nAltitude Accuracy: {4} \nAccuracy: {5} \nHeading: {6} \nSpeed: {7}",
position.Timestamp, position.Latitude, position.Longitude,
position.Altitude, position.AltitudeAccuracy, position.Accuracy, position.Heading, position.Speed);
}
catch (Exception ex)
{
await DisplayAlert("Uh oh", "Something went wrong, but don't worry we captured for analysis! Thanks.", "OK");
}
finally
{
gps_deneme.IsEnabled = true;
}
}
That will get the location , once. The plug-in has great documentation and links to example projects , I suggest you read them