{"id":586,"date":"2018-02-23T23:40:13","date_gmt":"2018-02-23T15:40:13","guid":{"rendered":"http:\/\/60.205.208.74\/2018\/02\/23\/ios%e5%9c%b0%e5%9b%be%e5%bc%80%e5%8f%91\/"},"modified":"2018-02-23T23:40:13","modified_gmt":"2018-02-23T15:40:13","slug":"ios%e5%9c%b0%e5%9b%be%e5%bc%80%e5%8f%91","status":"publish","type":"post","link":"https:\/\/www.puzi7.net\/?p=586","title":{"rendered":"iOS\u5730\u56fe\u5f00\u53d1"},"content":{"rendered":"<span itemprop=\"description\"><div class=\"article-body\">\n<div class=\"article-intro\" id=\"content\">\n<h1>IOS\u5730\u56fe\u5f00\u53d1<\/h1>\n<hr>\n<h2>\u7b80\u4ecb<\/h2>\n<p>IOS\u5730\u56fe\u5e2e\u52a9\u6211\u4eec\u5b9a\u4f4d\u4f4d\u7f6e\uff0cIOS\u5730\u56fe\u4f7f\u7528 MapKit \u6846\u67b6\u3002<\/p>\n<h3>\u5b9e\u4f8b\u6b65\u9aa4<\/h3>\n<p>1.\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684 View based application<\/p>\n<p>2.\u9009\u62e9\u9879\u76ee\u6587\u4ef6\uff0c\u7136\u540e\u9009\u62e9\u76ee\u6807\uff0c\u7136\u540e\u6dfb\u52a0MapKit.framework.<\/p>\n<p>3.\u6dfb\u52a0 Corelocation.framework<\/p>\n<p>4.\u5411 ViewController.xib \u6dfb\u52a0\u5730\u56fe\u67e5\u770b\u548c\u521b\u5efa ibOutlet \u5e76\u4e14\u547d\u540d\u4e3amapView\u3002<\/p>\n<p>5.\u901a\u8fc7&#8221;File-&gt; New -&gt; File&#8230; -&gt; &#8220;\u9009\u62e9 Objective C class\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\uff0c\u5355\u51fb\u4e0b\u4e00\u6b65<\/p>\n<p>6.&#8221;sub class of&#8221;\u4e3a NSObject\uff0c\u7c7b\u4f5c\u547d\u540d\u4e3aMapAnnotation<\/p>\n<p>7.\u9009\u62e9\u521b\u5efa<\/p>\n<p>8.\u66f4\u65b0MapAnnotation.h \uff0c\u5982\u4e0b\u6240\u793a<\/p>\n<pre>\n#import &lt;Foundation\/Foundation.h&gt;\n#import &lt;MapKit\/MapKit.h&gt;\n\n@interface MapAnnotation : NSObject&lt;MKAnnotation&gt;\n@property (nonatomic, strong) NSString *title;\n@property (nonatomic, readwrite) CLLocationCoordinate2D coordinate;\n\n- (id)initWithTitle:(NSString *)title andCoordinate:\n  (CLLocationCoordinate2D)coordinate2d;\n\n@end\n<\/pre>\n<p>9.\u66f4\u65b0MapAnnotation.m \uff0c\u5982\u4e0b\u6240\u793a<\/p>\n<pre>\n#import \"MapAnnotation.h\"\n\n@implementation MapAnnotation\n-(id)initWithTitle:(NSString *)title andCoordinate:\n (CLLocationCoordinate2D)coordinate2d{    \n    self.title = title;\n    self.coordinate =coordinate2d;\n    return self;\n}\n@end\n<\/pre>\n<p>10.\u66f4\u65b0ViewController.h \uff0c\u5982\u4e0b\u6240\u793a<\/p>\n<pre>\n#import &lt;UIKit\/UIKit.h&gt;\n#import &lt;MapKit\/MapKit.h&gt;\n#import &lt;CoreLocation\/CoreLocation.h&gt;\n@interface ViewController : UIViewController&lt;MKMapViewDelegate&gt;\n{\n    MKMapView *mapView;\n}\n@end\n<\/pre>\n<p>11.\u66f4\u65b0ViewController.m \uff0c\u5982\u4e0b\u6240\u793a<\/p>\n<pre>\n#import \"ViewController.h\"\n#import \"MapAnnotation.h\"\n\n@interface ViewController ()\n\n@end\n\n@implementation ViewController\n\n- (void)viewDidLoad\n{\n   [super viewDidLoad];\n   mapView = [[MKMapView alloc]initWithFrame:\n   CGRectMake(10, 100, 300, 300)];\n   mapView.delegate = self;\n   mapView.centerCoordinate = CLLocationCoordinate2DMake(37.32, -122.03);\n   mapView.mapType = MKMapTypeHybrid;\n   CLLocationCoordinate2D location;\n   location.latitude = (double) 37.332768;\n   location.longitude = (double) -122.030039;\n   \/\/ Add the annotation to our map view\n   MapAnnotation *newAnnotation = [[MapAnnotation alloc]\n   initWithTitle:@\"Apple Head quaters\" andCoordinate:location];\n   [mapView addAnnotation:newAnnotation];\n   CLLocationCoordinate2D location2;\n   location2.latitude = (double) 37.35239;\n   location2.longitude = (double) -122.025919;\n   MapAnnotation *newAnnotation2 = [[MapAnnotation alloc] \n   initWithTitle:@\"Test annotation\" andCoordinate:location2];\n   [mapView addAnnotation:newAnnotation2];\n   [self.view addSubview:mapView];\n}\n\/\/ When a map annotation point is added, zoom to it (1500 range)\n- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views\n{\n   MKAnnotationView *annotationView = [views objectAtIndex:0];\n   id &lt;MKAnnotation&gt; mp = [annotationView annotation];\n   MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance\n   ([mp coordinate], 1500, 1500);\n   [mv setRegion:region animated:YES];\n   [mv selectAnnotation:mp animated:YES];\n}\n\n- (void)didReceiveMemoryWarning\n{\n    [super didReceiveMemoryWarning];\n    \/\/ Dispose of any resources that can be recreated.\n}\n\n@end\n<\/pre>\n<h3>\u8f93\u51fa<\/h3>\n<p>\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u8f93\u51fa\u7ed3\u679c\u5982\u4e0b<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.runoob.com\/wp-content\/uploads\/2013\/11\/mapOutput1.jpg\" alt=\"mapOutput1\" width=\"250\" height=\"492\" class=\"alignnone size-full wp-image-4298\" srcset=\"http:\/\/www.runoob.com\/wp-content\/uploads\/2013\/11\/mapOutput1.jpg 250w, http:\/\/www.runoob.com\/wp-content\/uploads\/2013\/11\/mapOutput1-152x300.jpg 152w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\"><\/p>\n<p>\u5f53\u6211\u4eec\u5411\u4e0a\u6eda\u52a8\u5730\u56fe\u65f6\uff0c\u8f93\u51fa\u7ed3\u679c\u5982\u4e0b<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"attachment-full\" alt=\"mapOutput2\" src=\"http:\/\/www.runoob.com\/wp-content\/uploads\/2013\/11\/mapOutput2.jpg\" width=\"250\" height=\"511\" data-pinit=\"registered\"><\/p>\n<\/p><\/div>\n<\/p><\/div>\n<span>","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\"><span itemprop=\"description\">IOS\u5730\u56fe\u5f00\u53d1 \u7b80\u4ecb IOS\u5730\u56fe\u5e2e\u52a9\u6211\u4eec\u5b9a\u4f4d\u4f4d\u7f6e\uff0cIOS\u5730\u56fe\u4f7f\u7528 MapKit \u6846\u67b6\u3002 \u5b9e&hellip;<\/span><\/p>\n<p class=\"more-link-p btn-align-right\"><a class=\"green zoom-btn\" href=\"https:\/\/www.puzi7.net\/?p=586\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38,26],"tags":[74,93],"class_list":["post-586","post","type-post","status-publish","format-standard","hentry","category-ios","category-mobile","tag-ios","tag-mobile","zoom-theme-has-thumb"],"_links":{"self":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/586","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=586"}],"version-history":[{"count":0,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/586\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=586"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=586"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=586"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}