1. 报错:[MapController initController……];类似这种崩溃信息,可能是因为你自己的类名 MapController 与百度地图内部的一个类重名了,并且你会发现你的控制器里面并没有initController……这个方法。
解决:将名为 MapController 的控制器改名试试
2. duplicate… 意思是重复导入之类的
你是否使用cocoapods 管理三方库的,如果是那么,你可能根据百度地图的API 在 other link flags 中添加了-ObjC , (个人发现-ObjC 这个flag具有导入所需文件的作用)使得百度地图的某些东西重复导入了
解决:将-ObjC 删掉,如果将其删掉之后发现还有这一标识,那么就看有没有 $(inherited) (这个单词可能写得不太对)这一标识,如果有删掉就可以了
3. 自定义 大头针 的代理发放没走
- (BMKAnnotationView )mapView:(BMKMapView )mapView viewForAnnotation:(id )annotation
代理设置了,但是没走这个方法
解决:mapView 的 设置代理 百度API中是写在viewWillAppear:(BOOL)animated中的,这时地图添加大头针必须写在设置代理之后,不然就不会走
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[_mapView viewWillAppear];
_mapView.delegate = self; // 此处记得不用的时候需要置nil,否则影响内存的释放
// 添加一个PointAnnotation(大头针)
BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];
CLLocationCoordinate2D coor;
coor.latitude = 39.915;
coor.longitude = 116.404;
annotation.coordinate = coor;
annotation.title = @"这里是北京";
[_mapView addAnnotation:annotation];
}
4. 找不到 BMKClusterManager 这个类
百度地图里面有个 点聚合 这一功能,这个类在百度地图的SDK中并找不到,因为它是“解决加载大量点要素到地图上产生覆盖现象的问题,在Demo中开放了源码”,就是说这个类在下载的demo中可以找到
解决如果使用的话,可以从其demo中将对应的拖进去
5.热力图 -[BMKGradient generateColorMap:resultColorMap:]: unrecognized selector sent to instance
添加热力图时报这个 错误,走到[_mapView addHeatMap:heatMap]; 这句代码,程序就会崩溃
解决:在target ->build settings -> other link flags 中添加标记 -ObjC 标识
6.地理 逆编码
使用系统的类处理
//处理位置坐标更新
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
{
// NSLog(@"didUpdateUserLocation lat %f,long %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);
[_mapView updateLocationData:userLocation];
NSLog(@"%@",userLocation.location);
NSLog(@"%f",userLocation.location.coordinate.latitude);
CLLocation *location=[[CLLocation alloc]initWithLatitude:userLocation.location.coordinate.latitude longitude:userLocation.location.coordinate.longitude];
//需要逆地理编码的坐标位置
CLGeocoder *geocoder=[[CLGeocoder alloc]init];
[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
//判断是否有错误或者placemarks是否为空
if (error !=nil || placemarks.count==0) {
NSLog(@"%@",error);
return ;
}
for (CLPlacemark *placemark in placemarks) {
//赋值详细地址
NSLog(@"%@",placemark.name);
[_locService stopUserLocationService];
}
}];
}
7.检索功能中option.location = CLLocationCoordinate2D{39.915, 116.404};
报错
解决:
option.location = CLLocationCoordinate2DMake(39.915, 116.404);