public override void Selected(DialogViewController dvc, UITableView tableView, NSIndexPath path) { var vc = new MapKitViewController(this) { Autorotate = dvc.Autorotate }; if (MapView == null) { MapView = new MKMapView() { BackgroundColor = UIColor.White, AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight }; } MapView.Frame = new CGRect(UIScreen.MainScreen.ApplicationFrame.Left, UIScreen.MainScreen.ApplicationFrame.Top - 20, UIScreen.MainScreen.ApplicationFrame.Right, UIScreen.MainScreen.ApplicationFrame.Bottom - 20); if (mkHandleGetViewForAnnotation != null) { MapView.GetViewForAnnotation = delegate(MKMapView mapView, IMKAnnotation annotation) { return(mkHandleGetViewForAnnotation(mapView, annotation)); }; } if (mkHandleMapViewCalloutAccessoryControlTapped != null) { MapView.CalloutAccessoryControlTapped += mkHandleMapViewCalloutAccessoryControlTapped; } if (mkHandleMapViewDidSelectAnnotationView != null) { MapView.DidSelectAnnotationView += mkHandleMapViewDidSelectAnnotationView; } if (mkAnnotationObjects != null) { MapView.AddAnnotations(mkAnnotationObjects); } MapView.WillStartLoadingMap += delegate(object sender, EventArgs e) { NetworkActivity = true; }; MapView.MapLoaded += delegate(object sender, EventArgs e) { NetworkActivity = false; }; MapView.LoadingMapFailed += delegate(object sender, NSErrorEventArgs e) { // Display an error of sorts }; if (ReverseGeocoderDelegate != null) { if (MapView != null) { MapView.DidUpdateUserLocation += delegate(object sender, MKUserLocationEventArgs e) { if (MapView != null) { var ul = MapView.UserLocation.Location; if (ul != null) // May be null if user has not given permission { var gc = new MKReverseGeocoder(ul.Coordinate); gc.Delegate = ReverseGeocoderDelegate; gc.Start(); } } }; } } MapView.ShowsUserLocation = true; vc.NavigationItem.Title = Caption; vc.View.AddSubview(MapView); dvc.ActivateController(vc); }
public override void Selected (DialogViewController dvc, UITableView tableView, NSIndexPath path) { var vc = new MapKitViewController (this) { Autorotate = dvc.Autorotate }; if ( MapView == null ) { MapView = new MKMapView(){ BackgroundColor = UIColor.White, AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight }; } MapView.Frame = new CGRect(UIScreen.MainScreen.ApplicationFrame.Left, UIScreen.MainScreen.ApplicationFrame.Top - 20, UIScreen.MainScreen.ApplicationFrame.Right, UIScreen.MainScreen.ApplicationFrame.Bottom - 20); if (mkHandleGetViewForAnnotation != null ) { MapView.GetViewForAnnotation = delegate(MKMapView mapView, IMKAnnotation annotation) { return mkHandleGetViewForAnnotation(mapView, annotation); }; } if ( mkHandleMapViewCalloutAccessoryControlTapped != null ) { MapView.CalloutAccessoryControlTapped += mkHandleMapViewCalloutAccessoryControlTapped; } if (mkHandleMapViewDidSelectAnnotationView != null) { MapView.DidSelectAnnotationView += mkHandleMapViewDidSelectAnnotationView; } if ( mkAnnotationObjects != null ) { MapView.AddAnnotations(mkAnnotationObjects); } MapView.WillStartLoadingMap += delegate(object sender, EventArgs e) { NetworkActivity = true; }; MapView.MapLoaded += delegate(object sender, EventArgs e) { NetworkActivity = false; }; MapView.LoadingMapFailed += delegate(object sender, NSErrorEventArgs e) { // Display an error of sorts }; if ( ReverseGeocoderDelegate != null ) { if ( MapView != null ) { MapView.DidUpdateUserLocation += delegate(object sender, MKUserLocationEventArgs e) { if ( MapView != null ) { var ul = MapView.UserLocation.Location; if ( ul != null ) // May be null if user has not given permission { var gc = new MKReverseGeocoder(ul.Coordinate); gc.Delegate = ReverseGeocoderDelegate; gc.Start(); } } }; } } MapView.ShowsUserLocation = true; vc.NavigationItem.Title = Caption; vc.View.AddSubview(MapView); dvc.ActivateController (vc); }