Monotouch MapKit - annotations - adding a button to create bubbles

Does anyone know if there is anything at all to get a button on annotations?

I would like a location to be selected, so you can say .. select a location and get all the events in that place by clicking on the button.

Is it possible?

w: //

+7
iphone mapkit
source share
2 answers

Here, the code I used for my annotation includes a button on the right side of the bubble. You can set IBAction to push a new view onto the stack to display whatever you want.

- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation { MKPinAnnotationView *pinAnnotation = nil; if(annotation != mapView.userLocation) { static NSString *defaultPinID = @"myPin"; pinAnnotation = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID]; if ( pinAnnotation == nil ) pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease]; pinAnnotation.canShowCallout = YES; //instatiate a detail-disclosure button and set it to appear on right side of annotation UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; pinAnnotation.rightCalloutAccessoryView = infoButton; } return pinAnnotation; } 
+13
source share

I just helped someone with this in lens c, but I'm sure the concept is the same with mono. You need to create a custom MKAnnotationView object and override the GetViewForAnnotation method (viewforAnnotation in obj-c) of your MKMapViewDelegate class ... check another question .

When you create your own MKAnnotationView object, it is basically a UIView made for map annotations ... you can simply add your button and other information to the view and it will appear when the user clicks the annotation.

Here is an example of the rough code for the delegate method:

 public override MKAnnotationView GetViewForAnnotation( MKMapView mapView,NSObject annotation) { var annotationId = "location"; var annotationView = mapView.DequeueReusableAnnotation(annotationId); if (annotationView == null) { // create new annotation annotationView = new CustomAnnotationView(annotation, annotationId); } else { annotationView.annotation = annotation; } annotation.CanShowCallout = true; // setup other info for view // .......... return annotationView; } } 
+5
source share

All Articles