Skip to content

Instantly share code, notes, and snippets.

@Clancey
Created July 13, 2010 21:09
Show Gist options
  • Save Clancey/474532 to your computer and use it in GitHub Desktop.
Save Clancey/474532 to your computer and use it in GitHub Desktop.
public partial class AppDelegate : UIApplicationDelegate
{
CLLocationManager _iPhoneLocationManager = null;
LocationDelegate _locationDelegate = null;
// This method is invoked when the application has loaded its UI and its ready to run
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
this._iPhoneLocationManager = new CLLocationManager ();
this._locationDelegate = new LocationDelegate (this);
this._iPhoneLocationManager.Delegate = this._locationDelegate;
this._iPhoneLocationManager.StartUpdatingLocation();
this._iPhoneLocationManager.DesiredAccuracy = 150;
this._iPhoneLocationManager.DistanceFilter = 50;
return true;
}
void HandleLocationManagerUpdatedLocation (object sender, CLLocationUpdatedEventArgs e)
{
}
// This method is required in iPhoneOS 3.0
public override void OnActivated (UIApplication application)
{
}
public override void DidEnterBackground (UIApplication application)
{
_iPhoneLocationManager.StartMonitoringSignificantLocationChanges();
Console.WriteLine("Entered BAckground");
}
}
public class LocationDelegate : CLLocationManagerDelegate
{
AppDelegate _app;
public LocationDelegate (AppDelegate app) : base()
{
this._app = app;
}
//===============================
public override void UpdatedLocation (CLLocationManager manager
, CLLocation newLocation, CLLocation oldLocation)
{
Console.WriteLine(UIApplication.SharedApplication.ApplicationState + " : " + newLocation.HorizontalAccuracy + "," + newLocation.VerticalAccuracy + " : " + newLocation.Coordinate.Longitude.ToString () + "," + newLocation.Coordinate.Latitude.ToString(), DateTime.Now );
}
//===============================
//===============================
public override void UpdatedHeading (CLLocationManager manager, CLHeading newHeading)
{
}
//===============================
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment