【问题标题】:Multiple pins on MKMapviewMKMapview 上的多个引脚
【发布时间】:2011-07-22 18:44:32
【问题描述】:

是否可以在 MKmapview 上添加多个引脚?我已经添加了一个并完成了注释,我希望在 MKMapview 上添加多个引脚。请帮助我。

【问题讨论】:

  • 是的,这是可能的。您遇到的确切问题或错误是什么?你试过什么?显示您是如何添加单个注释的。
  • 我给出下面的代码来展示我的注释方法。
  • DDAnnotation *annotation = [[[DDAnnotation alloc] initWithCoordinate:theCoordinate addressDictionary:nil] autorelease]; DDAnnotation *annotation1 = [[[DDAnnotation alloc] initWithCoordinate:theCoordinate addressDictionary:nil] autorelease]; annotation.title = @"位置"; annotation1.title = @"位置"; annotation.subtitle = [NSString stringWithFormat:@"%f ​​%f", annotation.coordinate.latitude, annotation.coordinate.longitude]; annotation1.subtitle = [NSString stringWithFormat:@"%f ​​%f", annotation1.coordinate.latitude, annotation.

标签: iphone ios mkmapview


【解决方案1】:

只需简单地使用 [mapView addAnnotations:] 代替 addAnnotation。 您必须为其提供一个注释数组。

【讨论】:

  • 或者直接调用 addAnnotation 多次。
  • 我已经尝试多次调用它。它不起作用。请更多帮助
【解决方案2】:

/// ExplainClass 是一个新的类,其中声明了坐标、标题、标题

解释类

@property (nonatomic, assign) CLLocationCoordinate2D coordinate; 
@property (nonatomic, copy) NSString *title; 
@property (nonatomic, copy) NSString *subtitle;

// 地图类

 MKMapView *mapView;
        MKCoordinateRegion region = { {0.0, 0.0}, {0.0, 0.0} };
        region.center.latitude = 22.569722 ;
        region.center.longitude = 88.369722;
        region.span.longitudeDelta = 0.01f;
        region.span.latitudeDelta = 0.01f;
        [mapView setRegion:region animated:YES];
    MKCoordinateRegion region1 = { {0.0, 0.0}, {0.0, 0.0} };
    region1.center.latitude = 37.786996 ;
    region1.center.longitude = -122.419281;
    region1.span.longitudeDelta = 0.01f;
    region1.span.latitudeDelta = 0.01f;
    [mapView setRegion:region1 animated:YES];


    [mapView setDelegate:self];



    ExplainClass *ann = [[ExplainClass alloc] init]; 
    ann.title = @" Kolkata";
    ann.subtitle = @"Mahatma Gandhi Road"; 
    ann.coordinate = region.center; 

   ExplainClass *ann1 = [[ExplainClass alloc] init];
    ann.title = @" Abc";
    ann.subtitle = @"Road";
    ann.coordinate = region1.center;



    [mapView addAnnotation:ann];
    [mapView addAnnotation:ann1];

【讨论】:

  • 上面的代码真的很好。故障确实帮助我快速理解功能。然而,为了改进答案,我所做的是有一个带有纬度/经度的数组。然后我在一个 for 循环中运行上面的代码,遍历我的 lat/long 数组。这确保没有任何重复的代码,就像上面的变量“region”和“ann”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-01-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-03
  • 2012-04-11
相关资源
最近更新 更多