1

複数のピン/場所(約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
4

2 に答える 2

0

それはすべて、ピンに関する情報をどのように入力して維持するかによって異なります。XML、JSON、plist、CoreData などを使用できます。

于 2012-11-14T21:17:37.733 に答える
0

オブジェクト のNSArrayにデータを入力して呼び出すことができます:NewClass

[mapview addAnnotations:arrayOfAnnotations];//(メソッドの最後の 's' に注意してください)

すべての注釈をマップビューに配置します。
明らかに、各注釈には異なる座標が必要です。

@Alexが言ったように座標を保存するには、好みの形式を選択できます。

于 2012-11-14T21:27:56.780 に答える