void tryCheckingNow() { if (CLLocationManager.LocationServicesEnabled == false) { Location = null; // location is not known LocationServicesStatus = LocationServicesStatusEnum.NotAuthorized; FailureInfo = "Not authorized to use location services (2)"; fireEvents(); return; } DateTime timeStarted = DateTime.Now; Task.Run(async() => { for (; ;) { await Task.Delay(100); if (TimeUpdated != null && TimeUpdated.Value >= timeStarted) { // stop listening // note: events had already been fired locationManager.StopUpdatingLocation(); return; } if (TimeUpdated != null && (DateTime.Now - TimeUpdated.Value).TotalMinutes < 5 && Location != null) { // location already known. no need to wait. fireEvents(); return; } if ((DateTime.Now - timeStarted).TotalSeconds > 5) { FailureInfo = "Timeout"; fireEvents(); return; } } }); // start listening locationManager.StartUpdatingLocation(); }
// public IntPtr Handle => throw new NotImplementedException(); public void Start() { // you can set the update threshold and accuracy if you want: //locationManager.DistanceFilter = 10d; // move ten meters before updating //locationManager.HeadingFilter = 3d; // move 3 degrees before updating // you can also set the desired accuracy: mLocationManager.DesiredAccuracy = 1000; // 1000 meters/1 kilometer // you can also use presets, which simply evalute to a double value: //locationManager.DesiredAccuracy = CLLocation.AccuracyNearestTenMeters; mLocationManager.Delegate = this; mLocationManager.RequestWhenInUseAuthorization(); if (CoreLocation.CLLocationManager.LocationServicesEnabled) { mLocationManager.StartUpdatingLocation(); } if (CoreLocation.CLLocationManager.HeadingAvailable) { mLocationManager.StartUpdatingHeading(); } }