private void OnAltitudeEvent(GpsAltitudeProvider provider, AltitudeEvent e) { try { if (lastKnownLocation != null) { var loc = lastKnownLocation; lastKnownLocation = new SimpleLocation(true, e.location.Altitude, loc.longitude, loc.latitude); } else { lastKnownLocation = new SimpleLocation(true, e.location.Altitude, e.location.Longitude, e.location.Latitude); } } catch (Exception ex) { Log.E(this, "Failed to resolve altitude event", ex); } }
/// <summary> /// Initializes the IIONManager to the given IION. /// </summary> /// <returns>The async.</returns> public async Task <InitializationResult> InitAsync() { if (Permission.Granted == ContextCompat.CheckSelfPermission(ion.context, Android.Manifest.Permission.AccessFineLocation)) { altitudeProvider = new GpsAltitudeProvider(ion.context.GetSystemService(Context.LocationService) as LocationManager); if (IsGooglePlayServicesInstalled()) { client = InitGooglePlayServices(); client.Connect(); var start = DateTime.Now; while (client.IsConnecting && !client.IsConnected) { if (DateTime.Now - start > TimeSpan.FromSeconds(5)) { Log.E(this, "Failed to connect to google play services: we are shutting them down and running on backup"); client.Disconnect(); client = null; break; } await Task.Delay(50); } } StartAutomaticLocationPolling(); } else { Log.E(this, "The user denied the location permission. We will not allow the location to update."); ion.appPrefs._location.allowsGps = false; } ion.appPrefs.prefs.RegisterOnSharedPreferenceChangeListener(this); return(new InitializationResult() { success = true, }); }