public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. // locator = new Geolocator{ DesiredAccuracy = 50 }; // // locator.StartListening(5000, 1, false); // locator.PositionChanged += (object sender, PositionEventArgs e) => { // Console.WriteLine ("Position Status: {0}", e.Position.Accuracy); // Console.WriteLine ("Position Latitude: {0}", e.Position.Latitude); // Console.WriteLine ("Position Longitude: {0}", e.Position.Longitude); // }; // locator.PositionError += (object sender, PositionErrorEventArgs e) => { // Console.WriteLine("Could not find position: {0}, {1}", e.Error, e.ToString() ); // }; actIndicator.Hidden = true; mapView.MapType = MKMapType.Standard; var clm = new CLLocationManager(); clm.RequestAlwaysAuthorization(); mapView.ShowsUserLocation = true; //currLocation = new CLLocationCoordinate2D(20.7592, -156.4572); // C# style event handler - can access class instance variables mapView.DidUpdateUserLocation += (object sender, MKUserLocationEventArgs e) => { Console.WriteLine(".NET Lat: {0}, Long: {1}, Alt: {2}", e.UserLocation.Coordinate.Latitude, e.UserLocation.Coordinate.Longitude, e.UserLocation.Location.Altitude); currLocation = e.UserLocation.Coordinate; if (firstLaunch) { mapView.SetRegion(MKCoordinateRegion.FromDistance(currLocation, 250, 250), true); firstLaunch = false; } else mapView.SetCenterCoordinate(currLocation, true); }; mapView.DidSelectAnnotationView += (object sender, MKAnnotationViewEventArgs e) => { var annotation = e.View.Annotation as BNRMapPoint; if (annotation != null) { Console.WriteLine(".NET DidSelectAnnotationView: {0}", annotation.Title); } }; // Strong Delegate method. Create delegate class as nested class of ViewCOntroller // Override need methods in that nested delegate class // mapDelegate = new WhereAmIMapDelegate(); // mapView.Delegate = mapDelegate; // Weak delegate method. use Export attribute with selector to override then implement method. // Whichever is assigned last wins and kills the other. // mapView.WeakDelegate = this; // textField.Delegate = new TextFieldDelegate(); textField.EditingDidEndOnExit += (object sender, EventArgs e) => { actIndicator.Hidden = false; if (!firstLaunch) { BNRMapPoint mp = new BNRMapPoint(textField.Text, currLocation); mapView.AddAnnotation(mp); textField.ResignFirstResponder(); textField.Text = ""; actIndicator.Hidden = true; } else { var locator = new Geolocator{ DesiredAccuracy = 50 }; locator.GetPositionAsync (timeout: 10000).ContinueWith (t => { CLLocationCoordinate2D coord = new CLLocationCoordinate2D(t.Result.Latitude, t.Result.Longitude); currLocation = coord; MKCoordinateRegion region = MKCoordinateRegion.FromDistance(currLocation, 250, 250); mapView.SetRegion(region, true); BNRMapPoint mp = new BNRMapPoint(textField.Text, currLocation); mapView.AddAnnotation(mp); textField.ResignFirstResponder(); textField.Text = ""; actIndicator.Hidden = true; }, TaskScheduler.FromCurrentSynchronizationContext()); } }; segControl.BackgroundColor = UIColor.White; segControl.ValueChanged += (object sender, EventArgs e) => { switch (segControl.SelectedSegment) { case 0: mapView.MapType = MKMapType.Standard; break; case 1: mapView.MapType = MKMapType.Satellite; break; case 2: mapView.MapType = MKMapType.Hybrid; break; default: break; } }; }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. // locator = new Geolocator{ DesiredAccuracy = 50 }; // // locator.StartListening(5000, 1, false); // locator.PositionChanged += (object sender, PositionEventArgs e) => { // Console.WriteLine ("Position Status: {0}", e.Position.Accuracy); // Console.WriteLine ("Position Latitude: {0}", e.Position.Latitude); // Console.WriteLine ("Position Longitude: {0}", e.Position.Longitude); // }; // locator.PositionError += (object sender, PositionErrorEventArgs e) => { // Console.WriteLine("Could not find position: {0}, {1}", e.Error, e.ToString() ); // }; actIndicator.Hidden = true; mapView.MapType = MKMapType.Standard; var clm = new CLLocationManager(); clm.RequestAlwaysAuthorization(); mapView.ShowsUserLocation = true; //currLocation = new CLLocationCoordinate2D(20.7592, -156.4572); // C# style event handler - can access class instance variables mapView.DidUpdateUserLocation += (object sender, MKUserLocationEventArgs e) => { Console.WriteLine(".NET Lat: {0}, Long: {1}, Alt: {2}", e.UserLocation.Coordinate.Latitude, e.UserLocation.Coordinate.Longitude, e.UserLocation.Location.Altitude); currLocation = e.UserLocation.Coordinate; if (firstLaunch) { mapView.SetRegion(MKCoordinateRegion.FromDistance(currLocation, 250, 250), true); firstLaunch = false; } else { mapView.SetCenterCoordinate(currLocation, true); } }; mapView.DidSelectAnnotationView += (object sender, MKAnnotationViewEventArgs e) => { var annotation = e.View.Annotation as BNRMapPoint; if (annotation != null) { Console.WriteLine(".NET DidSelectAnnotationView: {0}", annotation.Title); } }; // Strong Delegate method. Create delegate class as nested class of ViewCOntroller // Override need methods in that nested delegate class // mapDelegate = new WhereAmIMapDelegate(); // mapView.Delegate = mapDelegate; // Weak delegate method. use Export attribute with selector to override then implement method. // Whichever is assigned last wins and kills the other. // mapView.WeakDelegate = this; // textField.Delegate = new TextFieldDelegate(); textField.EditingDidEndOnExit += (object sender, EventArgs e) => { actIndicator.Hidden = false; if (!firstLaunch) { BNRMapPoint mp = new BNRMapPoint(textField.Text, currLocation); mapView.AddAnnotation(mp); textField.ResignFirstResponder(); textField.Text = ""; actIndicator.Hidden = true; } else { var locator = new Geolocator { DesiredAccuracy = 50 }; locator.GetPositionAsync(timeout: 10000).ContinueWith(t => { CLLocationCoordinate2D coord = new CLLocationCoordinate2D(t.Result.Latitude, t.Result.Longitude); currLocation = coord; MKCoordinateRegion region = MKCoordinateRegion.FromDistance(currLocation, 250, 250); mapView.SetRegion(region, true); BNRMapPoint mp = new BNRMapPoint(textField.Text, currLocation); mapView.AddAnnotation(mp); textField.ResignFirstResponder(); textField.Text = ""; actIndicator.Hidden = true; }, TaskScheduler.FromCurrentSynchronizationContext()); } }; segControl.BackgroundColor = UIColor.White; segControl.ValueChanged += (object sender, EventArgs e) => { switch (segControl.SelectedSegment) { case 0: mapView.MapType = MKMapType.Standard; break; case 1: mapView.MapType = MKMapType.Satellite; break; case 2: mapView.MapType = MKMapType.Hybrid; break; default: break; } }; }