开发者

Drop pin in center of the map

How do I drop a pin in center of开发者_如何学Python the map?


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];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜