複数のピン/場所(約50〜100)を持つアプリを作成しようとしています。どちらの方法が最も簡単な方法ですか?自分の場所を取得するためのデータベースを作成できますか?現時点では、うまく機能するコードがありますが、1つの場所/ピンしか表示されません。現在のコードにさらに追加するにはどうすればよいですか?または、前に述べたように、ある種のデータベースを使用する他の簡単な方法はありますか?
コードは次のとおりです。SecoundViewController.h:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface SecondViewController : UIViewController {
MKMapView *mapview;
}
@property (nonatomic, retain) IBOutlet MKMapView *mapview;
-(IBAction)setMap:(id)sender;
-(IBAction)getlocation;
@end
SecoundViewController.m:
#import "SecondViewController.h"
#import "NewClass.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
@synthesize mapview;
-(IBAction)getlocation {
mapview.showsUserLocation = YES;
}
-(IBAction)setMap:(id)sender {
switch (((UISegmentedControl *) sender).selectedSegmentIndex) {
case 0:
mapview.mapType = MKMapTypeStandard;
break;
case 1:
mapview.mapType = MKMapTypeSatellite;
break;
case 2:
mapview.mapType = MKMapTypeHybrid;
break;
default:
break;
}
}
-(void)viewDidLoad {
[super viewDidLoad];
[mapview setMapType:MKMapTypeStandard];
[mapview setZoomEnabled:YES];
[mapview setScrollEnabled:YES];
MKCoordinateRegion region = { {0.0, 0.0 }, {0.0, 0.0 } };
region.center.latitude = 56.15881;
region.center.longitude = 13.76454;
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapview setRegion:region animated:YES];
NewClass *ann = [[NewClass alloc] init];
ann.title = @"Harrys Pub & Restaurang";
ann.subtitle = @"Järnvägsgatan 7";
ann.coordinate = region.center;
[mapview addAnnotation:ann];
}
@end