地图的定位,记得不用定位的时候要关掉定位不然会一直定位,使电量使用过快。

- (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);
}

  自定义大头针,要先自定义大头针模型,其核心代码如下:

- (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会贴出来。

本文GitHub地址https://github.com/zhangkiwi/iOS_SN_BDMap-Test

05-11 03:19