Skip to content

Instantly share code, notes, and snippets.

@nicwise
Created November 4, 2011 19:57
Show Gist options
  • Save nicwise/1340321 to your computer and use it in GitHub Desktop.
Save nicwise/1340321 to your computer and use it in GitHub Desktop.
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