Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run Geolocator Even App Close (Android, IOS) #319

Open
shadowq7 opened this issue Dec 22, 2019 · 1 comment
Open

Run Geolocator Even App Close (Android, IOS) #319

shadowq7 opened this issue Dec 22, 2019 · 1 comment

Comments

@shadowq7
Copy link

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;
          }
      }
@chrisfoulds
Copy link

That will get the location , once.
The plug-in has great documentation and links to example projects , I suggest you read them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants