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);
     }
 }
Exemple #2
0
        public override int GetHashCode()
        {
            unchecked
            {
                const int HashingBase       = (int)2166136261;
                const int HashingMultiplier = 16777619;

                int hash = HashingBase;
                hash = (hash * HashingMultiplier) ^ GpsName.GetHashCode();
                hash = (hash * HashingMultiplier) ^ GpsStatus.GetHashCode();
                hash = (hash * HashingMultiplier) ^ Imei.GetHashCode();
                hash = (hash * HashingMultiplier) ^ LastDate.GetHashCode();
                hash = (hash * HashingMultiplier) ^ Battery.GetHashCode();
                hash = (hash * HashingMultiplier) ^ ElapsedTime.GetHashCode();
                hash = (hash * HashingMultiplier) ^ Distance.GetHashCode();
                hash = (hash * HashingMultiplier) ^ Imei.GetHashCode();
                hash = (hash * HashingMultiplier) ^ GoogleDistance.GetHashCode();
                hash = (hash * HashingMultiplier) ^ LastLatitude.GetHashCode();
                hash = (hash * HashingMultiplier) ^ LastLongitude.GetHashCode();
                hash = (hash * HashingMultiplier) ^ ((LatLngList != null) ? LatLngList.GetHashCode() : 0);
                return(hash);
            }
        }
 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();
             }
         }
     }
 }