地圖的定位,記得不用定位的時候要關掉定位否則會一直定位,使電量使用過快。git
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.mapView = [[BMKMapView alloc] initWithFrame:CGRectMake(0, 0, kwidth, kheigth)]; // [self.mapView setZoomLevel:14]; [self.view addSubview:self.mapView]; //初始化BMKLocationService _locService = [[BMKLocationService alloc]init]; _locService.delegate = self; //啓動LocationService [_locService startUserLocationService]; } //實現相關delegate 處理位置信息更新 //處理方向變動信息 - (void)didUpdateUserHeading:(BMKUserLocation *)userLocation { //NSLog(@"heading is %@",userLocation.heading); NSLog(@"%@--%@--%f--%f",userLocation.title,userLocation.subtitle,userLocation.location.altitude,userLocation.location.altitude); } //處理位置座標更新 - (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation { _mapView.showsUserLocation = YES;//顯示定位圖層 [_mapView updateLocationData:userLocation]; NSLog(@"didUpdateUserLocation lat %f,long %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude); }
自定義大頭針,要先自定義大頭針模型,其核心代碼以下:github
- (BMKAnnotationView *)mapView:(BMKMapView *)view viewForAnnotation:(id <BMKAnnotation>)annotation { static NSString *AnnotationViewID = @"annotationViewID"; MyPointAnnotation *myAnnotation = (MyPointAnnotation *)annotation; MyAnnotationView *annotationView = (MyAnnotationView *)[view dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID]; if (annotationView == nil) { annotationView = [[MyAnnotationView alloc] initWithFrame:CGRectMake(0, 0, 27, 30) viewForAnnotation:myAnnotation reuseIdentifier:AnnotationViewID]; annotationView.image = [UIImage imageNamed:@"定位.png"]; } else { annotationView.myAnnotation = myAnnotation; [annotationView setNeedsLayout]; } annotationView.annotation = myAnnotation; annotationView.canShowCallout = true; return annotationView; }
下面有一個總體的demo會貼出來。blog
本文GitHub地址https://github.com/zhangkiwi/iOS_SN_BDMap-Testget