ios Baiduの地図の使用(一般的な位置付け、反地理符号化)


iOSの位置付け-通常の位置付け(地図なし)-地理的な逆符号化(具体的な位置を得る)は、コードによって詳しく説明します。コードは以下の通りです。

#import <CoreLocation/CoreLocation.h>            CoreLocation   
<CLLocationManagerDelegate>           
//1.      
 //  app          
 //        /   (app   )
 //info.plist        (      ):
 //NSLocationWhenInUseUsageDescription        
 //NSLocationAlwaysUsageDescription   
 //2.LocationManager            
 _manager = [[CLLocationManager alloc] init];
 //manager  :          / app          
 //[CLLocationManager locationServicesEnabled]; //        
 //[CLLocationManager authorizationStatus]; //app          
 if (![CLLocationManager locationServicesEnabled] || [CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorizedWhenInUse) {
  [_manager requestWhenInUseAuthorization]; //              
 }
 _manager.delegate = self;
 _manager.desiredAccuracy = kCLLocationAccuracyBest;
 _manager.distanceFilter = 1.0f;
 [_manager startUpdatingLocation];
//         
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
 [_manager stopUpdatingLocation];
 CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
 [geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
  for (CLPlacemark * placemark in placemarks) {
   NSDictionary *test = [placemark addressDictionary];
   // Country(  ) State(  ) SubLocality( ) Name  
   NSLog(@"%@", [test objectForKey:@"Name"]);
  }
 }];
}

ios Baiduの地図の使用(一般的な位置付け、反地理符号化)
1.まずは基本的な地図機能を受け付けます。
地図の種類を新しく作ってください。xibはドラッグしてもいいです。こちらはコードの実現です。
 

_mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0,self.view.frame.size.width, self.view.frame.size.height)];//  mapVIew
 [self.view addSubview:_mapView];
#pragma mark -   mapView  
-(void)setMapViewProperty
{
 _mapView.mapType = BMKUserTrackingModeFollowWithHeading;
 _mapView.showsUserLocation = YES; //        (         )
 _mapView.zoomLevel = 16;//      
 _mapView.rotateEnabled = NO; //        
  
 [self passLocationValue];
}
#pragma mark -       
//           ,          (                  ,                 )
-(void)passLocationValue
{
 BMKCoordinateRegion viewRegion = BMKCoordinateRegionMake([UserLocationManager sharedInstance].clloction.coordinate, BMKCoordinateSpanMake(0.02f,0.02f));
 BMKCoordinateRegion adjustedRegion = [_mapView regionThatFits:viewRegion];
 [_mapView setRegion:adjustedRegion animated:YES];
  
}
#pragma mark -        
-(void)setUserImage
{
 //     
 BMKLocationViewDisplayParam* param = [[BMKLocationViewDisplayParam alloc] init];
 param.locationViewOffsetY = 0;//   
 param.locationViewOffsetX = 0;
 param.isAccuracyCircleShow =NO;//              
 param.isRotateAngleValid = NO;
 [_mapView updateLocationViewWithParam:param];
}
このように基本的な地図のインターフェイスは出てきました。
地図上でいくつかの要求をすると、BMKMapView Delegateが実現できます。以下はmapViewのいくつかの契約方法です。

**
 *               
 *@param mapview   View
 *@param animated     
 */
- (void)mapView:(BMKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
{
 //TODO
}
 
/**
 *               
 *@param mapview   View
 *@param animated     
 */
- (void)mapView:(BMKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
 //TODO
}
/**
 *               
 *@param mapview   View
 */
- (void)mapStatusDidChanged:(BMKMapView *)mapView
{
 //TODO
}
2.地図の位置付け
こちらは位置指定機能と地図mapVIewを独立に展開し、地理的移動位置の変化を管理します。

#import <Foundation/Foundation.h>
#import "BMapKit.h"
@interface UserLocationManager : NSObject <BMKMapViewDelegate,BMKLocationServiceDelegate>
{
 CLLocation *cllocation;
 BMKReverseGeoCodeOption *reverseGeoCodeOption;//     
}
@property (strong,nonatomic) BMKLocationService *locService;
//   
@property (strong,nonatomic) NSString *cityName;
//    
@property (nonatomic,assign) double userLatitude;
//    
@property (nonatomic,assign) double userLongitude;
//    
@property (strong,nonatomic) CLLocation *clloction;
//     
+ (UserLocationManager *)sharedInstance;
//              
- (void)initBMKUserLocation;
//    
-(void)startLocation;
//    
-(void)stopLocation;
@end
#import "UserLocationManager.h"
@implementation UserLocationManager
+ (UserLocationManager *)sharedInstance
{
 static UserLocationManager *_instance = nil;
 @synchronized (self) {
  if (_instance == nil) {
   _instance = [[self alloc] init];
  }
 }
 return _instance;
}
-(id)init
{
 if (self == [super init])
 {
  [self initBMKUserLocation];
 }
 return self;
}
#pragma               
/**
 *               
 */
- (void)initBMKUserLocation
{
 _locService = [[BMKLocationService alloc]init];
 _locService.delegate = self;
 [self startLocation];
}
#pragma       
/**
 *       
 */
-(void)startLocation
{
 [_locService startUserLocationService];
}
#pragma       
/**
 *       
 */
-(void)stopLocation
{
 [_locService stopUserLocationService];
}
#pragma BMKLocationServiceDelegate
/**
 *       ,      
 *@param userLocation       
 */
- (void)didUpdateUserLocation:(BMKUserLocation *)userLocation
{
  cllocation = userLocation.location;
 _clloction = cllocation;
 _userLatitude = cllocation.coordinate.latitude;
 _userLongitude = cllocation.coordinate.longitude;
 [self stopLocation];(                )
}
/**
 *      ,      
 */
- (void)didStopLocatingUser
{
;
}
/**
 *     ,      
 *@param error    
 */
- (void)didFailToLocateUserWithError:(NSError *)error
{
 [self stopLocation];
}
以上のコードは本文のios Baiduの地図の使用(普通の位置付け、反地理コード)です。皆さんの今後の仕事と学習に役に立ちたいです。