0

我想知道是否有可能做到这一点,或者如果不是,有什么替代方案?我需要一些需要在地图上显示的信息,但我遇到了麻烦...... MKPointAnnotation 提供了一个很好的界面,但我一次无法打开超过 1 个标注。谢谢!

4

2 回答 2

0

在注释中添加按钮并为按钮设置标签。您也可以将其与自定义注释一起使用,但底线方法与以下相同。您需要设置标识符(标签)以打开多个注释。

  - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {

     {

         MKPinAnnotationView *pin = (MKPinAnnotationView *) [self.map      dequeueReusableAnnotationViewWithIdentifier: @"restMap"];
         if (pin == nil) {
            pin = [[[MKPinAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"restMap"] autorelease];
          }

          else {
              pin.annotation = annotation;
               }

          // add cutom button by following way.
          UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeCustombutton];


          // you just need to find an integer value that matches your object in some way:
          // its index in your array of MKAnnotation items, or an id of some sort, etc

          NSInteger annotationValue = [self.annotations indexOfObject:annotation];

          // set the tag property of the button to the index
          detailButton.tag = annotationValue;

          pin.rightCalloutAccessoryView = detailButton;
          return pin;
    }




     -(IBAction)showDetailofannotation:(UIView*)sender {
       // get the tag value from the sender
        NSInteger annotationtag = sender.tag;
        MyAnnotationObject *selectedObject = [self.annotations objectAtIndex:annotationtag ];

   // now you know which detail view you want to show; the code that follows

        YourDetailViewController *detailView = [[YourDetailViewController alloc] initWithNibName:@"YourDetailViewController ", NSBundle:nil];
detailView.detailObject = selectedObject;

       [[self navigationController] pushViewController:detailView animated:YES];
        [detailView release];`
     }

希望对你有帮助..

于 2012-05-06T03:15:41.013 回答
0

我找到了解决方案:

您需要先阅读以下内容:

http://developer.apple.com/library/ios/#DOCUMENTATION/UserExperience/Conceptual/LocationAwarenessPG/AnnotatingMaps/AnnotatingMaps.html

然后这里有一个例子:

http://shawnsbits.com/blog/2011/04/12/custom-map-pins-for-mapkit/

关键是在 viewDidLoad 中加载带有自定义图像的注释数组,然后在 mapView:viewForAnnotation: 创建一个新的 MKAnnotationView 并通过将注释转换为传递给它的自定义注释来将图像加载到其中。

我希望这有帮助。对不起,如果它看起来有点混乱!

于 2012-05-06T13:24:42.533 回答