GeolocatorPlugin icon indicating copy to clipboard operation
GeolocatorPlugin copied to clipboard

Run Geolocator Even App Close (Android, IOS)

Open shadowq7 opened this issue 5 years ago • 1 comments

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

shadowq7 avatar Dec 22 '19 17:12 shadowq7

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

chrisfoulds avatar Dec 22 '19 18:12 chrisfoulds