开发者

Drop pin in center of the map

开发者 https://www.devze.com 2023-03-01 10:53 出处:网络
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

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

精彩评论

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

关注公众号