public override void GetLocation(Action <bool> action, bool isRefresh = false) { try { Actions.Add(action); if (!isRefresh && (!LastLatitude.Equals(0) || !LastLongitude.Equals(0))) { RaiseAppOnLocationChanged(true); } else { MainActivity.GetLocation(); } } catch (Exception e) { ExceptionHandler.Catch(e); } }
public override void GetLocation(Action <bool> action, bool isRefresh = false) { Actions.Add(action); if (!isRefresh && (!LastLatitude.Equals(0) || !LastLongitude.Equals(0))) { RaiseAppOnLocationChanged(true); } else { if (CLLocationManager.Status == CLAuthorizationStatus.Denied) { string title = AppResources.LocationServicesOff; string message = AppResources.TurnOnLocationMessage; IUIAlertViewDelegate alertViewDelegate = null; UIAlertView uiAlertView = new UIAlertView(title, message, alertViewDelegate, AppResources.Cancel, new[] { AppResources.Settings }); uiAlertView.Clicked += (sender, e) => { if (e.ButtonIndex == 1) { var settingsString = UIKit.UIApplication.OpenSettingsUrlString; var url = new NSUrl(settingsString); UIApplication.SharedApplication.OpenUrl(url); } else { if (action != null) { action.Invoke(false); } } }; uiAlertView.Show(); } else { CLLocationManager locMgr = new CLLocationManager(); locMgr.PausesLocationUpdatesAutomatically = false; if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) { locMgr.RequestAlwaysAuthorization(); } if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0)) { locMgr.AllowsBackgroundLocationUpdates = true; } if (CLLocationManager.LocationServicesEnabled) { locMgr.DistanceFilter = 5; locMgr.LocationsUpdated += (object sender2, CLLocationsUpdatedEventArgs e2) => { var location = e2.Locations.FirstOrDefault(); if (location != null) { this.LastLongitude = location.Coordinate.Longitude; this.LastLatitude = location.Coordinate.Latitude; RaiseAppOnLocationChanged(true); } }; locMgr.StartUpdatingLocation(); } } } }