Beispiel #1
0
        /// <summary>
        /// Initializes a new Geolocator object.
        /// </summary>
        public Geolocator()
        {
            LocationStatus = PositionStatus.NotInitialized;
#if __UNIFIED__
            _manager.DesiredAccuracy = CLLocation.AccuracyBest;
#if __IOS__ || __MAC__
#if __IOS__
            _manager.ActivityType = CLActivityType.Other;

            _manager.PausesLocationUpdatesAutomatically = false;
            _manager.AuthorizationChanged += manager_AuthorizationChanged;
#endif
            _manager.LocationUpdatesPaused   += Manager_LocationUpdatesPaused;
            _manager.LocationUpdatesResumed  += Manager_LocationUpdatesResumed;
            _manager.DeferredUpdatesFinished += Manager_DeferredUpdatesFinished;
#endif
            if (CLLocationManager.LocationServicesEnabled)
            {
#if __IOS__
                // ask for the authorization based on what is in the app manifest.
                if (NSBundle.MainBundle.InfoDictionary.ContainsKey(new NSString("NSLocationAlwaysUsageDescription")))
                {
                    _manager.AllowsBackgroundLocationUpdates = true;
                    _manager.InvokeOnMainThread(_manager.RequestAlwaysAuthorization);
                }
                else
                {
                    _manager.InvokeOnMainThread(_manager.RequestWhenInUseAuthorization);
                }
#elif __TVOS__
                _manager.InvokeOnMainThread(_manager.RequestWhenInUseAuthorization);
#endif
            }
            else
            {
                LocationStatus = PositionStatus.Disabled;
            }
#elif TIZEN
            _locator.ServiceStateChanged += _locator_ServiceStateChanged;
#elif WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE
            _locator.StatusChanged += _locator_StatusChanged;
#elif WIN32
#endif
        }