Created
November 4, 2011 19:57
-
-
Save nicwise/1340321 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CLLocationManager locationManager = null; | |
public void GetForCurrentLocation (double distance, Action<List<Marker>, int> OnRegionUpdate) | |
{ | |
if (CLLocationManager.LocationServicesEnabled) | |
{ | |
if (locationManager == null) | |
{ | |
locationManager = new CLLocationManager (); | |
locationManager.DesiredAccuracy = CLLocation.AccuracyHundredMeters; | |
locationManager.UpdatedLocation += delegate(object sender, CLLocationUpdatedEventArgs e) { | |
Util.Log ("UpdatedLocation. Accuracy: {0:0.000}", e.NewLocation.HorizontalAccuracy); | |
if (e.NewLocation.HorizontalAccuracy < 150 || inaccurateCount > 4) | |
{ | |
//Do soemthign with it | |
locationManager.StopUpdatingLocation (); | |
lastFoundLocation = e.NewLocation.Coordinate; | |
} else | |
{ | |
Util.FlashStatus ("Waiting for a more accurate GPS fix."); | |
} | |
}; | |
locationManager.Failed += delegate(object sender, NSErrorEventArgs e) { | |
if (e.Error.Code == (int)CLError.Denied) | |
{ | |
locationManager.StopUpdatingLocation (); | |
Util.Log ("Failed to get location: " + e.Error.LocalizedDescription); | |
ShowError (false, "Error finding your location. You need to turn location services on"); | |
} | |
if (e.Error.Code == (int)CLError.LocationUnknown) | |
{ | |
} | |
}; | |
} | |
locationManager.StartUpdatingLocation (); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment