{"id":436,"date":"2014-11-18T11:08:09","date_gmt":"2014-11-18T03:08:09","guid":{"rendered":"http:\/\/www.yusian.com\/blog\/?p=436"},"modified":"2016-07-14T18:17:52","modified_gmt":"2016-07-14T10:17:52","slug":"%e7%99%be%e5%ba%a6%e5%9c%b0%e5%9b%be%e4%bd%bf%e7%94%a8%e7%ac%ac%e4%ba%94%e8%ae%b2%ef%bc%9a%e5%a4%a7%e5%a4%b4%e9%92%88%e4%bd%bf%e7%94%a8%ef%bc%88%e5%9c%b0%e5%9b%be%e6%a0%87%e6%b3%a8%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.yusian.com\/blog\/project\/2014\/11\/18\/110809436.html","title":{"rendered":"\u767e\u5ea6\u5730\u56fe\u4f7f\u7528\u7b2c\u4e94\u8bb2\uff1a\u5927\u5934\u9488\u4f7f\u7528\uff08\u5730\u56fe\u6807\u6ce8\uff09"},"content":{"rendered":"<p>1\u3001\u52a0\u8f7d\u57fa\u672c\u5730\u56fe\u89c6\u56fe\u5c55\u793a<\/p>\n<p>2\u3001\u521b\u5efa\u4e00\u4e2a\u5927\u5934\u9488\u6a21\u578b\uff08\u4e3b\u8981\u662f\u7ecf\u7eac\u5ea6\uff09\u6d89\u53ca\u5230\u7684\u7c7b\u6709BMKPointAnnotation\u3001BMKAnnotationView\u3001BMKPinAnnotationView<br \/>\nBMKPointAnnotation\uff1a\u5927\u5934\u9488\u6a21\u578b\uff0c\u7528\u6765\u63cf\u8ff0\u5927\u5934\u9488\u7684\u5750\u6807\u7b49\u4fe1\u606f\uff1b<br \/>\nBMKAnnotationView\uff1a\u6807\u6ce8\u89c6\u56fe\uff0c\u5305\u542b\u6807\u6ce8\u4e0a\u9762\u7684\u6807\u9898\u3001\u5b50\u6807\u9898\u3001\u53ca\u76f8\u5173\u6309\u94ae\u7b49\uff1b<br \/>\nBMKPinAnnotationView\uff1a\u5927\u5934\u9488\u89c6\u56fe\uff0c\u7ee7\u627f\u81eaBMKAnnotationView\uff0c\u53ef\u4ee5\u7406\u89e3\u4e3a\u5927\u5934\u9488\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u6807\u6ce8\uff1b<\/p>\n<p>3\u3001\u5c06\u5927\u5934\u9488\u6dfb\u52a0\u5230\u5730\u56fe\uff0c\u5230\u6b64\u4e3a\u6b62\u4e8b\u5b9e\u4e0a\u5df2\u7ecf\u641e\u5b9a\uff0c\u5730\u56fe\u4e0a\u80fd\u6b63\u5e38\u663e\u793a\u521a\u521a\u6240\u6807\u6ce8\u7684\u5927\u5934\u9488\u4e86\uff0c\u5982\u4e0b\u6548\u679c\u56fe\u6240\u793a\uff1a<!--more--><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.yusian.com\/blog\/wp-content\/uploads\/2016\/07\/iOS-\u6a21\u62df\u5668\u5c4f\u5e55\u5feb\u7167\u201c2014\u5e7411\u670818\u65e5-\u4e0a\u534811.02.21\u201d.jpg\" alt=\"iOS-\u6a21\u62df\u5668\u5c4f\u5e55\u5feb\u7167\u201c2014\u5e7411\u670818\u65e5-\u4e0a\u534811.02.21\u201d\" width=\"320\" height=\"480\" class=\"alignnone size-full wp-image-437\" \/><\/p>\n<p>4\u3001\u6b64\u5916\uff0cmapView\u8fd8\u6709\u53e6\u5916\u4e24\u4e2a\u4ee3\u7406\u65b9\u6cd5\u53ef\u4ee5\u5bf9\u5927\u5934\u9488\u8fdb\u884c\u540e\u7eed\u7684\u5904\u7406\uff0c\u6bd4\u5982\u5927\u5934\u9488\u989c\u8272\uff0c\u52a8\u753b\u6548\u679c\uff08\u4ece\u5929\u800c\u964d\uff09\u7b49<br \/>\n&#8211; (void)mapView:(BMKMapView *)mapView didAddAnnotationViews:(NSArray *)views<br \/>\n&#8211; (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation<\/p>\n<p>5\u3001\u5173\u952e\u4ee3\u7801\u793a\u4f8b<\/p>\n<pre lang=\"objc\" line=\"1\">#import \"SAViewController.h\"\n#import \"BMapKit.h\"\n\n@interface SAViewController () <BMKPoiSearchDelegate, BMKMapViewDelegate>\n\n@property (nonatomic, strong) BMKMapView *mapView;                   \/\/ \u5730\u56fe\n\n@property (nonatomic, strong) BMKPointAnnotation *pointAnnotation;   \/\/ \u5927\u5934\u9488\n\n@end\n\n@implementation SAViewController\n\n- (void)viewDidLoad\n{\n    [super viewDidLoad];\n    \n    \/\/ \u521b\u5efa\u4e00\u4e2a\u5730\u56fe\u6dfb\u52a0\u5230\u63a7\u5236\u5668\u89c6\u56fe\u4e0a\n    self.mapView.frame = self.view.frame;\n    [self.view addSubview:self.mapView];\n    \n    \/\/ \u521b\u5efa\u4e00\u4e2a\u5927\u5934\u9488\u6a21\u578b\uff0c\u8bbe\u7f6e\u5927\u5934\u9488\u7ecf\u7eac\u5750\u6807\n    self.pointAnnotation = [[BMKPointAnnotation alloc] init];\n    self.pointAnnotation.title = @\"\u5927\u5934\u9488\";\n    self.pointAnnotation.subtitle = @\"\u4e00\u4e2a\u795e\u5947\u7684\u4e1c\u897f\";\n    self.pointAnnotation.coordinate = (CLLocationCoordinate2D){39.9, 116.4};\n    [self.mapView addAnnotation:self.pointAnnotation];\n    \n}\n\n- (void)viewWillAppear:(BOOL)animated\n{\n    [super viewWillAppear:animated];\n    [self.mapView viewWillAppear];\n}\n\n- (void)viewWillDisappear:(BOOL)animated\n{\n    [super viewWillDisappear:animated];\n    [self.mapView viewWillDisappear];\n}\n\n#pragma mark mapView\u7684Get\u65b9\u6cd5\uff0c\u5ef6\u65f6\u52a0\u8f7d\n- (BMKMapView *)mapView\n{\n    if (!_mapView) {\n        _mapView = [[BMKMapView alloc] init];\n        _mapView.delegate = self;\n    }\n    return _mapView;\n}\n\n#pragma mark \u6dfb\u52a0\u6807\u6ce8\u65f6\u8c03\u7528\n- (void)mapView:(BMKMapView *)mapView didAddAnnotationViews:(NSArray *)views\n{\n    NSLog(@\"\u5730\u56fe\u6dfb\u52a0\u6807\u6ce8\u65f6\u4f1a\u8c03\u7528\uff01\");\n}\n\n#pragma mark \u4e3a\u6807\u6ce8\u751f\u6210\u65b0\u7684\u89c6\u56fe\n-(BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation\n{\n    NSLog(@\"\u5730\u56fe\u91cd\u65b0\u751f\u6210\u6807\u6ce8\u8499\u5c42\u65f6\u8c03\u7528\uff01\");\n    \n    \/\/ \u7c7b\u4f3cTableViewCell\uff0c\u53ef\u4ece\u7f13\u5b58\u4e2d\u91cd\u590d\u5229\u7528\u7684View\n    BMKPinAnnotationView *annotationView;\n    annotationView = (BMKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@\"Annotation\"];\n    if (!annotationView) {\n        \/\/ BMKPinAnnotationView\u662fBMKAnnotationView\u7684\u5b50\u7c7b\uff08\u5927\u5934\u9488\u6807\u6ce8\u7c7b\uff09\n        annotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@\"Annotation\"];\n        \/\/ \u8bbe\u7f6e\u5927\u5934\u9488\u7684\u989c\u8272\u4e3a\u7eff\u8272\n        annotationView.pinColor = BMKPinAnnotationColorGreen;\n    }\n    return annotationView;\n}\n@end<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001\u52a0\u8f7d\u57fa\u672c\u5730\u56fe\u89c6\u56fe\u5c55\u793a 2\u3001\u521b\u5efa\u4e00\u4e2a\u5927\u5934\u9488\u6a21\u578b\uff08\u4e3b\u8981\u662f\u7ecf\u7eac\u5ea6\uff09\u6d89\u53ca\u5230\u7684\u7c7b\u6709BMKPointAnnotation\u3001BMKAnnotationView\u3001BMKPinAnnotationView BMKPointAnnotation\uff1a\u5927\u5934\u9488\u6a21\u578b\uff0c\u7528\u6765\u63cf\u8ff0\u5927\u5934\u9488\u7684\u5750\u6807\u7b49\u4fe1\u606f\uff1b BMKAnnotationView\uff1a\u6807\u6ce8\u89c6\u56fe\uff0c\u5305\u542b\u6807\u6ce8\u4e0a\u9762\u7684\u6807\u9898\u3001\u5b50\u6807\u9898\u3001\u53ca\u76f8\u5173\u6309\u94ae\u7b49\uff1b BMKPinAnnotationView\uff1a\u5927\u5934\u9488\u89c6\u56fe\uff0c\u7ee7\u627f\u81eaBMKAnnotationView\uff0c\u53ef\u4ee5\u7406\u89e3\u4e3a\u5927\u5934\u9488\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u6807\u6ce8\uff1b 3\u3001\u5c06\u5927\u5934\u9488\u6dfb\u52a0\u5230\u5730\u56fe\uff0c\u5230\u6b64\u4e3a\u6b62\u4e8b\u5b9e\u4e0a\u5df2\u7ecf\u641e\u5b9a\uff0c\u5730\u56fe\u4e0a\u80fd\u6b63\u5e38\u663e\u793a\u521a\u521a\u6240\u6807\u6ce8\u7684\u5927\u5934\u9488\u4e86\uff0c\u5982\u4e0b\u6548\u679c\u56fe\u6240\u793a\uff1a<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[13],"class_list":["post-436","post","type-post","status-publish","format-standard","hentry","category-project","tag-bdmap"],"_links":{"self":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/436","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/comments?post=436"}],"version-history":[{"count":0,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/436\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/media?parent=436"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/categories?post=436"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/tags?post=436"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}