void OnCalloutAccessoryControlTapped(object sender, MKMapViewAccessoryTappedEventArgs e) { CustomMKAnnotationView customView = e.View as CustomMKAnnotationView; if (!string.IsNullOrWhiteSpace(customView.Url)) { UIApplication.SharedApplication.OpenUrl(new Foundation.NSUrl(customView.Url)); } }
void OnDidSelectAnnotationView(object sender, MKAnnotationViewEventArgs e) { CustomMKAnnotationView customView = e.View as CustomMKAnnotationView; customPinView = new UIView(); if (customView.Name.Equals("Xamarin")) { customPinView.Frame = new CGRect(0, 0, 200, 84); var image = new UIImageView(new CGRect(0, 0, 200, 84)); image.Image = UIImage.FromFile("pin.png"); customPinView.AddSubview(image); customPinView.Center = new CGPoint(0, -(e.View.Frame.Height + 75)); e.View.AddSubview(customPinView); } }
protected override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { MKAnnotationView annotationView = null; if (annotation is MKUserLocation || annotation == null) { return(null); } var customPin = GetCustomPin(annotation as MKPointAnnotation); if (customPin == null) { throw new Exception("Custom pin not found"); } annotationView = mapView.DequeueReusableAnnotation(customPin.Name); //if (annotationView == null || customPin.IsSelected) //{ annotationView = new CustomMKAnnotationView(annotation, customPin.Name); if (customPin.IsSelected) { annotationView.Image = UIImage.FromFile("pinnero.png"); } else { annotationView.Image = UIImage.FromFile("pinblu.png"); } annotationView.CalloutOffset = new CGPoint(0, 0); annotationView.LeftCalloutAccessoryView = new UIImageView(UIImage.FromFile("pin.png")); annotationView.RightCalloutAccessoryView = UIButton.FromType(UIButtonType.DetailDisclosure); ((CustomMKAnnotationView)annotationView).Name = customPin.Name; ((CustomMKAnnotationView)annotationView).Url = customPin.Url; //} annotationView.CanShowCallout = true; return(annotationView); }