{"id":190922,"date":"2023-06-18T21:23:27","date_gmt":"2023-06-18T13:23:27","guid":{"rendered":"https:\/\/www.idc.net\/help\/190922\/"},"modified":"2023-06-18T21:23:27","modified_gmt":"2023-06-18T13:23:27","slug":"%e5%90%8e%e6%b5%aa%e4%ba%91ios%e6%95%99%e7%a8%8b%ef%bc%9aios%e5%9c%b0%e5%9b%be%e5%bc%80%e5%8f%91","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/190922\/","title":{"rendered":"\u540e\u6d6a\u4e91IOS\u6559\u7a0b\uff1aiOS\u5730\u56fe\u5f00\u53d1"},"content":{"rendered":"<h2>IOS\u5730\u56fe\u5f00\u53d1<\/h2>\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\"File-&gt; New -&gt; File... -&gt; \"\u9009\u62e9 Objective C class\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\uff0c\u5355\u51fb\u4e0b\u4e00\u6b65<\/p>\n<p>6.\"sub class of\"\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>#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>#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>#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>#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 style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/atts.IDC.NET.cn\/attachments\/day_171121\/201711211711368369.jpg\" class=\"aligncenter\"><\/p>\n<p>\u5f53\u6211\u4eec\u5411\u4e0a\u6eda\u52a8\u5730\u56fe\u65f6\uff0c\u8f93\u51fa\u7ed3\u679c\u5982\u4e0b<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/atts.IDC.NET.cn\/attachments\/day_171121\/201711211711418578.jpg\" class=\"aligncenter\"><\/p>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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\u4f8b\u6b65\u9aa4 1.\u521b\u5efa\u4e00\u4e2a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":190923,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[189686],"tags":[],"class_list":["post-190922","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ios"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/190922","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=190922"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/190922\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media\/190923"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=190922"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=190922"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=190922"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}