在地图视图上设置多个接点/位置最简单/最好的方法是什么



我正在尝试制作一个具有多个引脚/位置(大约50-100个)的应用程序。哪条路最容易走?我能有一个数据库来获取我的位置吗?目前,我有一个非常有效的代码,但它只显示一个位置/引脚。如何在当前代码上添加更多内容?或者,正如我之前所说,使用某种数据库还有其他更简单的方法吗?

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

SecondViewController.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

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

您可以填充NewClass对象的NSArray并调用:

[mapview addAnnotations:arrayOfAnnotations];//(注意方法中的最后一个"s")

将所有注释放在地图视图上
显而易见,每个注释都应该有不同的坐标。

如@Alex所说,您可以选择自己喜欢的格式来存储坐标。

最新更新