iOS 바 이 두 맵 에서 현재 위치 가 져 오기

9040 단어 바 이 두 지도
//

//  ViewController.m

//  BaiDuDemo

//

//  Created by Chocolate. on 15-3-2.

//  Copyright (c) 2015  redasen. All rights reserved.

//



#import "ViewController.h"

#import "BMapKit.h"



@interface ViewController () <BMKGeoCodeSearchDelegate,BMKMapViewDelegate, BMKLocationServiceDelegate>

@property (strong, nonatomic) BMKMapView *mapView;

@property (strong, nonatomic) BMKGeoCodeSearch *search;

@property (strong, nonatomic) BMKLocationService *locService;

@end



@implementation ViewController

{

    BMKUserLocation *myLocation;

}



- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    _mapView = [[BMKMapView alloc] initWithFrame:self.view.bounds];

    [self.view addSubview:_mapView];

    

    _search = [[BMKGeoCodeSearch alloc]init];

    

    //   BMKLocationService

    _locService = [[BMKLocationService alloc]init];

    _locService.delegate = self;

    //  LocationService

    [_locService startUserLocationService];

}



-(void)viewWillAppear:(BOOL)animated

{

    [_mapView viewWillAppear];

    _mapView.delegate = self;

     _search.delegate = self;

}



-(void)viewDidAppear:(BOOL)animated

{

    [_mapView setShowsUserLocation:YES];

}



-(void)viewWillDisappear:(BOOL)animated

{

    [_mapView setShowsUserLocation:NO];

    _mapView.delegate = nil;

    _search.delegate = nil;

}



- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}



#pragma mark - BMKLocationServiceDelegate

/**

 *        ,      

 */

- (void)willStartLocatingUser

{

    

}



/**

 *      ,      

 */

- (void)didStopLocatingUser

{

    CLLocationCoordinate2D pt = (CLLocationCoordinate2D){0, 0};

    

    pt = (CLLocationCoordinate2D){myLocation.location.coordinate.latitude, myLocation.location.coordinate.longitude};

    

    BMKReverseGeoCodeOption *option = [[BMKReverseGeoCodeOption alloc]init];

    option.reverseGeoPoint = pt;

    BOOL result = [_search reverseGeoCode:option];

    

    if(result)

    {

        NSLog(@" geo      ");

    }

    else

    {

        NSLog(@" geo      ");

    }

}



/**

 *       ,      

 *@param userLocation       

 */

- (void)didUpdateUserHeading:(BMKUserLocation *)userLocation

{

    NSLog(@"heading is %@",userLocation.heading);

}



/**

 *       ,      

 *@param userLocation       

 */

- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation

{

    if (userLocation != nil) {

        

        NSLog(@"get location success");

        myLocation = userLocation;

        _mapView.showsUserLocation = NO;

        [_locService stopUserLocationService];

    }

    

    NSLog(@"didUpdateUserLocation lat %f,long %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);

}



/**

 *     ,      

 *@param error    

 */

- (void)didFailToLocateUserWithError:(NSError *)error

{

    

}



#pragma mark - BMKGeoCodeSearchDelegate



/**

 *          

 *@param searcher     

 *@param result    BMKGeoCodeSearch 

 *@param error    ,@see BMKSearchErrorCode

 */

- (void)onGetGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error

{

    

}



/**

 *           

 *@param searcher     

 *@param result     

 *@param error    ,@see BMKSearchErrorCode

 */

- (void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error

{

    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:result.address delegate:self cancelButtonTitle:@"  " otherButtonTitles:nil, nil];

    [alert show];

}



@end

좋은 웹페이지 즐겨찾기