コード例 #1
0
        public LocationManager()
        {
            _manager = new CLLocationManager();
            _locationChangeRegistry = LocationChangeRegistry.Instance;
            _manager.PausesLocationUpdatesAutomatically = false;

            // iOS 8 has additional permissions requirements
            if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            {
                Console.WriteLine("GeoClient is running in iOS 8 or higher. 'RequestAlwaysAuthorization' is requested async.");
                _manager.RequestAlwaysAuthorization(); // works in background
            }

            if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
            {
                Console.WriteLine("GeoClient is running in iOS 9 or higher. 'AllowsBackgroundLocationUpdates' is set to true.");
                _manager.AllowsBackgroundLocationUpdates = true;
            }

            _manager.LocationsUpdated += (sender, e) =>
            {
                Console.WriteLine("Got a location update from location manager.");
                if (e.Locations.Length > 0)
                {
                    var lastLocation = e.Locations[e.Locations.Length - 1];
                    InformRegistryAboutLocationUpdate(lastLocation);
                }
                else
                {
                    Console.WriteLine("Got a location update without locations!");
                }
            };
        }
コード例 #2
0
 public AndroidLocationService()
 {
     _powerManager            = Application.Context.GetSystemService(PowerService) as PowerManager;
     _locationChangeRegistry  = LocationChangeRegistry.Instance;
     _locationProviderFactory = new LocationProviderFactory();
 }