-1

我在我的应用程序中创建了一个 MapView,它可以放大用户的当前位置,并且效果很好。请参阅下面的代码:

.h 文件

@interface MapViewController : UIViewController  <MKMapViewDelegate> 

@property (nonatomic, strong) IBOutlet MKMapView *mapView;

@end

.m 文件

- (void)viewDidLoad {

[super viewDidUnload];

    [mapView setMapType:MKMapTypeStandard];
    [mapView setZoomEnabled:YES];
    [mapView setScrollEnabled:YES];



    self.mapView.delegate = self;
}

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation

{
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 800, 800);
    [self.mapView setRegion:[self.mapView regionThatFits:region] animated:YES];


MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
point.coordinate = userLocation.coordinate;
point.title = @"You Are Here";
point.subtitle = @"Your current location";

[self.mapView addAnnotation:point];
}

此代码将注释放置在用户当前位置的位置。但是,从这里开始,我想添加多个注释(以便用户可以看到它们周围的关键位置)。为了做到这一点,我需要添加/更改什么代码?

谢谢。

4

1 回答 1

0

这可以通过很多很多不同的方式来完成。这取决于您的数据源和需求

这是添加两个的方法

MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
point.coordinate = userLocation.coordinate;
point.title = @"You Are Here";
point.subtitle = @"Your current location";

[self.mapView addAnnotation:point];


MKPointAnnotation *point2 = [[MKPointAnnotation alloc] init];
point2.coordinate = aDifferentCoordinate;
point2.title = @"You Are Here";
point2.subtitle = @"Your current location";

[self.mapView addAnnotation:point2];

这是一种在同一点添加一千的方法

int i;
for(i = 0; i < 1000; i++)
{
    MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
    point.coordinate = userLocation.coordinate;
    point.title = @"You Are Here";
    point.subtitle = @"Your current location";

   [self.mapView addAnnotation:point];
}
于 2013-01-26T08:16:58.940 回答