哪个是在mapview上拥有多个引脚/位置的最简单/最好的方法?

时间:2012-11-14 21:13:55

标签: iphone xcode loops map xcode4.5

我正在尝试创建一个具有多个引脚/位置(约50-100)的应用。哪种方式最简单?我可以从某种数据库获取我的位置吗? 目前我的代码效果很好,但它只显示一个位置/引脚。如何在当前代码上添加更多内容?或者正如我之前所说,对于某种数据库,还有其他更简单的方法吗?

这是代码: 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

2 个答案:

答案 0 :(得分:0)

这完全取决于您打算如何输入和维护有关引脚的信息。 您可以使用XML,JSON,plist,CoreData ......

答案 1 :(得分:0)

您可以填充NSArray NewClass[mapview addAnnotations:arrayOfAnnotations];个对象并致电:

{{1}} //(注意方法中的最终's')

将所有注释放在mapview上  显然,每个注释应该有不同的坐标。

为了存储坐标,@ Alex说你可以选择你喜欢的格式。