iOS百度地図は、アプリケーションが許可されているかどうか、地理的位置の正逆符号化を判断します.


<span style="font-family:Arial, Helvetica, sans-serif;font-size:18px;"> 、 </span>
<span style="font-family: Arial, Helvetica, sans-serif;">#pragma mark ---   </span>
-(void)isOpenBmkLocationService:(void(^)(BOOL state))completion{
    
    if ([CLLocationManager locationServicesEnabled] && ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways
         || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse)) {
            
            completion(YES);
            NSLog(@" ")
            
        }
    else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied){
        [SVProgressHUD showErrorWithStatus:@" iPhone \" - - \" "];
        NSLog(@" ");
    }
}

二、地理位置逆符号化
ヘッダファイル
#import <BaiduMapAPI_Search/BMKGeocodeSearch.h>

エンコーディング
/**
 *   
 *
 *  @param completion  
 */
-(void)BaiDuMapGeoCodeSearch:(getCityName)cityBlock{
    
    self.block = cityBlock;
    
    _codeSearch = [[BMKGeoCodeSearch alloc] init];
    /**
     *   nil , 
     */
    _codeSearch.delegate = self;
    /**
     *   
     */
    BMKReverseGeoCodeOption * codeOption = [[BMKReverseGeoCodeOption alloc] init];
    /**
     *   ( )
     */
    codeOption.reverseGeoPoint = self.location;
    [_codeSearch reverseGeoCode:codeOption];
    
}
-(void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error{
    
    if (self.block && [result.addressDetail.city length]) {
        self.block(result.addressDetail.city);
    }
}

三、地理位置正符号化
エージェントの参照と解放
-(void)viewWillAppear:(BOOL)animated{
    [self.mapView viewWillAppear];
    self.mapView.delegate = self;
     _codeSearch.delegate = self;
}
-(void)viewWillDisappear:(BOOL)animated{
    [self.mapView viewWillDisappear];
    self.mapView.delegate = nil;
    self.codeSearch.delegate = nil;
}
エンコーディング
-(void)BaiDuMapGeoCodeSearch:(MapViewBlock)mapBlock{
    
    _codeSearch = [[BMKGeoCodeSearch alloc] init];
    
    BMKGeoCodeSearchOption * codeOption = [[BMKGeoCodeSearchOption alloc] init];
    
//    codeOption.city = @" ";
    codeOption.address = @" ";
    
    
    [self.codeSearch geoCode:codeOption];
    
    self.block = mapBlock;
}
-(void)onGetGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error{
    
    if (self.block && result.location.longitude != 0.0) {
        
        self.block(result.location);
        
    }
    
}
呼び出し後の表示
ヘッダファイル
#import <BaiduMapAPI_Map/BMKAnnotation.h>
#import <BaiduMapAPI_Map/BMKPointAnnotation.h>
#import <BaiduMapAPI_Map/BMKPinAnnotationView.h>
[self BaiDuMapGeoCodeSearch:^(CLLocationCoordinate2D coordinate) {
        // 
        self.mapView.centerCoordinate = coordinate;
        // 
        [self createPointAnnotationWithCoordinate:coordinate];
        
    }];
/**
 *   
 */
-(BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation{
    
    if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
        BMKPinAnnotationView * annotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"annotation"];
        annotationView.pinColor = BMKPinAnnotationColorPurple;
        //  
        annotationView.animatesDrop = YES;
        //  
        annotationView.draggable = YES;
        return annotationView;
    }
    
    return nil;
}
/**
 *     
 *
 *  @param location
 */
-(BMKPointAnnotation *)createPointAnnotationWithCoordinate:(CLLocationCoordinate2D)coordate{
    BMKPointAnnotation * point = [[BMKPointAnnotation alloc] init];
    point.coordinate = coordate;
    [self.mapView addAnnotation:point];
    return point;
}