4

我有一个地图视图,并且有 10 个商店位置的数据来自网络服务。我只想推送到我的详细视图以显示点击商店的地址、电话和其他信息。

detailview当用户在 mapkit 上点击或触摸内部注释时,我需要将数据传递给我。我的里面有10个注解,mapview首先我想知道,我怎么理解或者如何获取点击了哪个注解的annotationID?

这是我返回别针的方法

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

    if ([annotation isKindOfClass:[MKUserLocation class]]) return nil;

    static NSString* AnnotationIdentifier = @"AnnotationIdentifier";

    MKPinAnnotationView* pinView = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];

     pinView.animatesDrop=YES;
     pinView.canShowCallout=YES;
     pinView.pinColor=MKPinAnnotationColorPurple;

     UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
     [rightButton setTitle:annotation.title forState:UIControlStateNormal];

     [rightButton addTarget:self
     action:@selector(showDetails:)
     forControlEvents:UIControlEventTouchUpInside];

     pinView.rightCalloutAccessoryView = rightButton;

    return pinView;
}
   /* and my action method for clicked or tapped annotation: */

 - (IBAction)showDetails:(id)sender{

      NSLog(@"Annotation Click");

      [[mtMap selectedAnnotations]objectAtIndex:0];
      magazaDetayViewController *detail = [[magazaDetayViewController 
      alloc]initWithNibName:@"magazaDetayViewController" bundle:nil];

      detail.sehir=@"";
      detail.magazaAdi=@"";
      detail.adres=@"";
      detail.telefon=@"";
      detail.fax=@"";
      [self.navigationController pushViewController:detail animated:YES];

 }

如果我只能获得单击的注释索引,我可以用我的数组填充详细属性。如果这是不可能的,还有其他方法吗?

4

3 回答 3

9

首先在您的注释视图委托中制作一个按钮以进入详细视图,如下所示:

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

MKPinAnnotationView *mypin = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"current"];
mypin.pinColor = MKPinAnnotationColorPurple;
mypin.backgroundColor = [UIColor clearColor];
UIButton *goToDetail = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
mypin.rightCalloutAccessoryView = myBtn;
mypin.draggable = NO;
mypin.highlighted = YES;
mypin.animatesDrop = TRUE;
mypin.canShowCallout = YES;
return mypin;
}

现在,只要点击 annotationView 中的按钮,就使用下面的委托,下面的委托将被调用,您可以从那里轻松获取点击了哪个特定的注释按钮

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view 
 calloutAccessoryControlTapped:(UIControl *)control
{
annotation *annView = view.annotation;
detailedViewOfList *detailView = [[detailedViewOfList alloc]init];
detailView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
detailView.address = annView.address;
detailView.phoneNumber = annView.phonenumber;
[self presentModalViewController:detailView animated:YES];
}

这里 annotaion 是一个导入 MKAnotaion.h 的类,address 和 phonenumber 是 annotaion 类的属性,您可以制作更多的属性,而 detailView 类的 address 和 phoneNumber 属性很强大。这样您就可以传递值。希望对你有帮助!

于 2012-05-22T09:11:27.603 回答
0

Bellow是MapView......的委托方法

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{

}

当用户点击方法调用上方的注释引脚时,如果方法在 .m 文件中定义,则首先MKMapViewDelegate在 .h 文件中声明委托

您还可以从 google place API 获取标题或副标题和 ID ....链接是... https://developers.google.com/maps/documentation/places/

于 2012-05-22T08:51:07.210 回答
0
for(int i=0; i<[arrLat count];i++) {

CLLocationCoordinate2D theCoordinate1; 
konumpin* myAnnotation1=[[konumpin alloc] init]; 

theCoordinate1.latitude = [[arrLong objectAtIndex:i] doubleValue]; 

theCoordinate1.longitude = [[arrLat objectAtIndex:i] doubleValue]; 

myAnnotation1.coordinate=theCoordinate1; 
myAnnotation1.title=[arrMagaza objectAtIndex:i]; 
[annotations addObject:myAnnotation1]; 

} 

[mtMap addAnnotations:annotations];
于 2014-02-14T18:08:16.233 回答