How to keep data associated with MKAnnotation from being lost after a callout pops up and user taps disclosure button?

In the showPinDetails: method, you can get the currently selected annotation from the map view’s selectedAnnotations property. That property is an NSArray but since the map view only allows one annotation to be selected at a time, you would just use the object at index 0. For example: – (void)showPinDetails:(id)sender { if (mapView.selectedAnnotations.count == 0) … Read more

How to display 2 lines of text for subtitle of MKAnnotation and change the image for the button on the right?

plz use this – (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation { if ([annotation isKindOfClass:[MKUserLocation class]]) return nil; if ([annotation isKindOfClass:[CustomAnnotation class]]) { CustomAnnotation *customAnnotation = (CustomAnnotation *) annotation; MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@”CustomAnnotation”]; if (annotationView == nil) annotationView = customAnnotation.annotationView; else annotationView.annotation = annotation; //Adding multiline subtitle code UILabel *subTitlelbl = [[UILabel alloc]init]; subTitlelbl.text = @”sri … Read more

How to create Custom MKAnnotationView and custom annotation title and subtitle

To create a custom annotation view (your replacement for the standard pin), you can just set the image property of the MKAnnotationView in the viewForAnnotation method: – (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { if ([annotation isKindOfClass:[MKUserLocation class]]) { return nil; } else if ([annotation isKindOfClass:[YourAnnotationClassHere class]]) // use whatever annotation class you used when creating … Read more

Multiple annotation callouts displaying in MKMapView

Note that there is a method on MKMapView (not MKAnnotationView) for selecting an annotation programmatically that works more or less as you would expect: – (void)selectAnnotation:(id < MKAnnotation >)annotation animated:(BOOL)animated However, it automatically deselects any currently annotation at the same time so this doesn’t solve your problem. Oddly, there is a property on MKMapView that … Read more

How to add more details in MKAnnotation in iOS

Take a look at creating a custom MKAnnotationView object… it is basically a UIView that is tailored for map annotations. In that object you could have your 4 custom labels. In your MKMapViewDelegate class, you implement the viewForAnnotation method: – (CustomMapAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { CustomMapAnnotationView *annotationView = nil; // determine the type of … Read more

MKMapView: Instead of Annotation Pin, a custom view

When you want to use your own image for an annotation view, you should create an MKAnnotationView instead of an MKPinAnnotationView. MKPinAnnotationView is a subclass of MKAnnotationView so it has an image property but it generally overrides that and draws a pin image (that’s what it’s for). So change the code to: -(MKAnnotationView *)mapView:(MKMapView *)mV … Read more