{"id":433,"date":"2014-11-18T14:55:36","date_gmt":"2014-11-18T06:55:36","guid":{"rendered":"http:\/\/www.yusian.com\/blog\/?p=433"},"modified":"2016-07-14T18:15:37","modified_gmt":"2016-07-14T10:15:37","slug":"%e7%99%be%e5%ba%a6%e5%9c%b0%e5%9b%be%e4%bd%bf%e7%94%a8%e7%ac%ac%e5%85%ad%e8%ae%b2%ef%bc%9a%e6%a3%80%e7%b4%a2%e5%8f%8a%e5%a4%a7%e5%a4%b4%e9%92%88%e7%9a%84%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/www.yusian.com\/blog\/project\/2014\/11\/18\/145536433.html","title":{"rendered":"\u767e\u5ea6\u5730\u56fe\u4f7f\u7528\u7b2c\u516d\u8bb2\uff1a\u68c0\u7d22\u53ca\u5927\u5934\u9488\u7684\u4f7f\u7528"},"content":{"rendered":"<p><strong>\u57fa\u672c\u6b65\u9aa4\uff1a<\/strong><\/p>\n<p>1\u3001\u521b\u5efa\u5730\u56fe\u89c6\u56fe\uff1b<br \/>\n2\u3001\u4f7f\u7528\u5b9a\u4f4d\u7684\u529f\u80fd\u83b7\u53d6\u5230\u5f53\u524d\u4f4d\u7f6e\uff1b<br \/>\n3\u3001\u5229\u7528\u68c0\u7d22\u529f\u80fd\uff0c\u5728\u5f53\u524d\u4f4d\u7f6e\u68c0\u7d22\u67d0\u4e2a\u5173\u952e\u5b57\uff08\u5982\uff1a\u9152\u5427\uff09\uff1b<br \/>\n4\u3001\u5229\u7528\u68c0\u7d22\u5230\u7684\u7ed3\u679c\uff0c\u521b\u5efa\u5927\u5934\u9488\u5e76\u5728\u5730\u56fe\u4e0a\u5c55\u793a\uff1b<\/p>\n<p><strong>\u5173\u952e\u7684\u7c7b\uff1a<\/strong><\/p>\n<p>1\u3001BMKMapView\uff1a\u5730\u56fe<br \/>\n2\u3001BMKLocationService\uff1a\u5b9a\u4f4d<br \/>\n3\u3001BMKPoiSearch\uff1aPOI\u68c0\u7d22\uff08POI\u5373Point Of Interest\u53ef\u4ee5\u7ffb\u8bd1\u4e3a\u5174\u8da3\u70b9\uff09<br \/>\n4\u3001BMKNearbySearchOption\uff1a\u5468\u8fb9\u641c\u7d22\u9009\u9879\uff0c\u914d\u5408POI\u68c0\u7d22\u4f7f\u7528\uff0c\u505a\u4e3aPOI\u68c0\u7d22\u7684\u6570\u636e\u6a21\u578b<br \/>\n5\u3001BMKPointAnnotation\uff1a\u5927\u5934\u9488\uff0c\u53ef\u76f4\u63a5\u6dfb\u52a0\u5230\u5730\u56fe\u4e0a\u505a\u4e3a\u6807\u6ce8\u4f7f\u7528<\/p>\n<p><strong>\u5173\u952e\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>#pragma mark \u5b9a\u4f4d\u670d\u52a1\u7684\u4ee3\u7406\u65b9\u6cd5\uff0c\u5982\u679c\u83b7\u53d6\u5230\u4f4d\u7f6e\u4fe1\u606f\u5219\u8c03\u7528<br \/>\n&#8211; (void)didUpdateUserLocation:(BMKUserLocation *)userLocation<br \/>\n#pragma mark POI\u68c0\u7d22\u4ee3\u7406\u65b9\u6cd5\uff0c\u5982\u679c\u68c0\u7d22\u5230\u7ed3\u679c\u5219\u8c03\u6b64\u65b9\u6cd5<br \/>\n-(void)onGetPoiResult:(BMKPoiSearch *)searcher result:(BMKPoiResult *)poiResult errorCode:(BMKSearchErrorCode)errorCode<br \/>\n\u4ee3\u7801\u793a\u4f8b\uff1a<!--more--><\/p>\n<pre lang=\"objc\" line=\"1\">#import \"SAViewController.h\"\n#import \"BMapKit.h\"\n\n@interface SAViewController () <BMKPoiSearchDelegate, BMKMapViewDelegate, BMKLocationServiceDelegate>\n\n@property (nonatomic, strong) BMKMapView         *mapView;   \/\/ \u5730\u56fe\n@property (nonatomic, strong) BMKPoiSearch       *poiSearch; \/\/ POI\u68c0\u7d22\n@property (nonatomic, strong) BMKLocationService *location;  \/\/ \u5b9a\u4f4d\u670d\u52a1\n\n@end\n\n@implementation SAViewController\n\n- (void)viewDidLoad\n{\n    [super viewDidLoad];\n    \/\/ \u6dfb\u52a0\u5730\u56fe\u89c6\u56fe\n    self.mapView.frame = self.view.frame;\n    [self.view addSubview:self.mapView];\n    \n    \/\/ \u5f00\u542f\u5b9a\u4f4d\u670d\u52a1\n    self.location = [[BMKLocationService alloc] init];\n    self.location.delegate = self;\n    [self.location startUserLocationService];\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- (BMKMapView *)mapView\n{\n    if (!_mapView) {\n        _mapView = [[BMKMapView alloc] init];\n        _mapView.delegate = self;\n    }\n    return _mapView;\n}\n\n- (BMKPoiSearch *)poiSearch\n{\n    if (!_poiSearch) {\n        _poiSearch = [[BMKPoiSearch alloc] init];\n        _poiSearch.delegate = self;\n    }\n    return _poiSearch;\n}\n\n#pragma mark \u5b9a\u4f4d\u670d\u52a1\u7684\u4ee3\u7406\u65b9\u6cd5\uff0c\u5982\u679c\u83b7\u53d6\u5230\u4f4d\u7f6e\u4fe1\u606f\u5219\u8c03\u7528\n- (void)didUpdateUserLocation:(BMKUserLocation *)userLocation\n{\n    \/\/ \u5b9a\u4f4d\u6210\u529f\u540e\u5c06\u5f53\u524d\u7684\u4f4d\u7f6e\u8bbe\u7f6e\u4e3a\u5730\u56fe\u7684\u4e2d\u5fc3\u70b9\n    self.mapView.centerCoordinate = userLocation.location.coordinate;\n    \/\/ \u5730\u56fe\u7684\u7f29\u653e\u6bd4\u4f8b\u768417 \uff083 ~ 19\u53d6\u503c\uff09\n    self.mapView.zoomLevel = 17;\n    \/\/ \u505c\u6b62\u5b9a\u4f4d\u670d\u52a1\n    [self.location stopUserLocationService];\n    \n    \/\/ \u521b\u5efa\u4e00\u4e2a\u641c\u7d22\u9009\u9879\uff08\u68c0\u7d22\u7684\u6570\u636e\u6a21\u578b\uff09\n    BMKNearbySearchOption *nearOption = [[BMKNearbySearchOption alloc] init];\n    \/\/ \u68c0\u7d22\u5173\u952e\u5b57\uff1a\u201c\u9152\u5427\u201d\n    nearOption.keyword = @\"\u9152\u5427\";\n    \/\/ \u68c0\u7d22\u4f4d\u7f6e\u4e3a\u5f53\u524d\u5b9a\u4f4d\u5230\u7684\u5750\u6807\uff08\u5373\u6211\u5f53\u524d\u7684\u4f4d\u7f6e\uff09\n    nearOption.location = userLocation.location.coordinate;\n    \/\/ \u5f00\u59cb\u68c0\u7d22\n    [self.poiSearch poiSearchNearBy:nearOption];\n}\n\n#pragma mark POI\u68c0\u7d22\u4ee3\u7406\u65b9\u6cd5\uff0c\u5982\u679c\u68c0\u7d22\u5230\u7ed3\u679c\u5219\u8c03\u6b64\u65b9\u6cd5\n-(void)onGetPoiResult:(BMKPoiSearch *)searcher result:(BMKPoiResult *)poiResult errorCode:(BMKSearchErrorCode)errorCode\n{\n    \/\/ \u68c0\u7d22\u5230\u76f8\u5173\u4fe1\u606f\u540e\uff0c\u5bf9\u7ed3\u679c\u8fdb\u884c\u904d\u5386\uff08\u7ed3\u679c\u4e3aBMKPoiInfo\u7c7b\u578b\u7684\u6570\u7ec4\uff09\n    for (BMKPoiInfo *info in poiResult.poiInfoList) {\n        \/\/ \u904d\u5386\u7ed3\u679c\u4e2d\u7684\u6bcf\u4e00\u4e2a\u6570\u636e\u6a21\u578b\u5e76\u521b\u5efa\u4e00\u4e2a\u5927\u5934\u9488\n        BMKPointAnnotation *annotation = [[BMKPointAnnotation alloc] init];\n        \/\/ \u5927\u5934\u9488\u7684\u4f4d\u7f6e\u4e3a\u7ed3\u679c\u7684\u5750\u6807\uff08\u7ecf\u7eac\u5ea6\uff09\n        annotation.coordinate = info.pt;\n        \/\/ \u5927\u5934\u9488\u7684\u6807\u9898\u4e3a\u7ed3\u679c\u7684\u540d\u79f0\n        annotation.title = info.name;\n        \/\/ \u5927\u5934\u9488\u7684\u5b50\u6807\u9898\u4e3a\u7ed3\u679c\u7684\u5730\u5740\n        annotation.subtitle = info.address;\n        \/\/ \u5728\u5927\u5934\u9488\u6dfb\u52a0\u5230\u5730\u56fe\u4e0a\u5c55\u793a\n        [self.mapView addAnnotation:annotation];\n    }\n}\n\n@end<\/pre>\n<p>\u6548\u679c\u56fe\uff1a<\/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\u670820\u65e5-\u4e0a\u534810.06.26\u201d.jpg\" alt=\"iOS-\u6a21\u62df\u5668\u5c4f\u5e55\u5feb\u7167\u201c2014\u5e7411\u670820\u65e5-\u4e0a\u534810.06.26\u201d\" width=\"320\" height=\"480\" class=\"alignnone size-full wp-image-434\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u57fa\u672c\u6b65\u9aa4\uff1a 1\u3001\u521b\u5efa\u5730\u56fe\u89c6\u56fe\uff1b 2\u3001\u4f7f\u7528\u5b9a\u4f4d\u7684\u529f\u80fd\u83b7\u53d6\u5230\u5f53\u524d\u4f4d\u7f6e\uff1b 3\u3001\u5229\u7528\u68c0\u7d22\u529f\u80fd\uff0c\u5728\u5f53\u524d\u4f4d\u7f6e\u68c0\u7d22\u67d0\u4e2a\u5173\u952e\u5b57\uff08\u5982\uff1a\u9152\u5427\uff09\uff1b 4\u3001\u5229\u7528\u68c0\u7d22\u5230\u7684\u7ed3\u679c\uff0c\u521b\u5efa\u5927\u5934\u9488\u5e76\u5728\u5730\u56fe\u4e0a\u5c55\u793a\uff1b \u5173\u952e\u7684\u7c7b\uff1a 1\u3001BMKMapView\uff1a\u5730\u56fe 2\u3001BMKLocationService\uff1a\u5b9a\u4f4d 3\u3001BMKPoiSearch\uff1aPOI\u68c0\u7d22\uff08POI\u5373Point Of Interest\u53ef\u4ee5\u7ffb\u8bd1\u4e3a\u5174\u8da3\u70b9\uff09 4\u3001BMKNearbySearchOption\uff1a\u5468\u8fb9\u641c\u7d22\u9009\u9879\uff0c\u914d\u5408POI\u68c0\u7d22\u4f7f\u7528\uff0c\u505a\u4e3aPOI\u68c0\u7d22\u7684\u6570\u636e\u6a21\u578b 5\u3001BMKPointAnnotation\uff1a\u5927\u5934\u9488\uff0c\u53ef\u76f4\u63a5\u6dfb\u52a0\u5230\u5730\u56fe\u4e0a\u505a\u4e3a\u6807\u6ce8\u4f7f\u7528 \u5173\u952e\u65b9\u6cd5\uff1a #pragma mark \u5b9a\u4f4d\u670d\u52a1\u7684\u4ee3\u7406\u65b9\u6cd5\uff0c\u5982\u679c\u83b7\u53d6\u5230\u4f4d\u7f6e\u4fe1\u606f\u5219\u8c03\u7528 &#8211; (void)didUpdateUserLocation:(BMKUserLocation *)userLocation #pragma mark POI\u68c0\u7d22\u4ee3\u7406\u65b9\u6cd5\uff0c\u5982\u679c\u68c0\u7d22\u5230\u7ed3\u679c\u5219\u8c03\u6b64\u65b9\u6cd5 -(void)onGetPoiResult:(BMKPoiSearch *)searcher result:(BMKPoiResult *)poiResult errorCode:(BMKSearchErrorCode)errorCode \u4ee3\u7801\u793a\u4f8b\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-433","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\/433","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=433"}],"version-history":[{"count":0,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/433\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/media?parent=433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/categories?post=433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/tags?post=433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}