百度地圖接入注意

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);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章