-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

これは、さまざまな方法で実行できます。それはあなたのデータソースとニーズに依存します

2つ追加する方法は次のとおりです

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];

同じポイントで1000を追加する方法は次のとおりです

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 に答える