1

How do I drop a pin in center of the map?

codereviewanskquestions
  • 13,460
  • 29
  • 98
  • 167
  • [This](http://stackoverflow.com/questions/1917383/how-do-i-drop-a-pin-with-mapkit) is what you're looking for. - There is no standard pin available to drop though. – Julian Apr 29 '11 at 22:21

1 Answers1

4

You first need to create a class that implements the MKAnnotation protocol; this is effectively the "data" of the annotation (pin) and has little to do with the visual representation. You can then create an instance of this class, set its coordinate to the centre of the map, add it to your MKMapView, and render it using an MKPinAnnotationView instance.

// In your view controller, assuming you've created the "MyAnnotation" class.
- (void)viewDidLoad {
  [super viewDidLoad];

  MyAnnotation *annotation = [[[MyAnnotation alloc] init] autorelease];
  annotation.coordinate:self.mapView.centerCoordinate;
  [self.mapView addAnnotation:annotation];
}

- (MKAnnotationView *)mapView:(MKMapView *)mapView
    viewForAnnotation:(id <MKAnnotation>)annotation {
  // Remember to reuse annotation views by calling MKMapView's
  // dequeueReusableAnnotationViewWithIdentifier:!
  return [[[MKPinAnnotationView alloc] initWithAnnotation:annotation
      reuseIdentifier:@"string"] autorelease];
}