`
iaiai
  • 浏览: 2144088 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

IOS 用百度地图v2.4.1 AIP代码获取定位信息

 
阅读更多
1.去官方下载百度地图API包..

2.lipo -create Release-iphoneos/libbaidumapapi.a Release-iphonesimulator/libbaidumapapi.a -output libbaidumapapi.a
在命令行下执行此方法把模拟器跟真机用的两个库文件合并成一个.

3.把百度的头文件导入到项目中


然后把刚才生成的libbaidumapapi.a导入到项目中的Frameworks中:

并导入图中相应的库

4.配置参数

根据图中位置找到ther Linker Flags,并设置图中参数。

把项目中随便一个m类改成后缀为mm

5.代码
在AppDelegate.m中的application中添加:
BMKMapManager* _mapManager = [[BMKMapManager alloc]init];
    // 如果要关注网络及授权验证事件,请设定
    BOOL ret = [_mapManager start:@"key"  generalDelegate:nil];
    if (!ret) {
        NSLog(@"manager start failed!");
    }

//记得导入#import "BMapKit.h"此包


在使用的ViewController.h中定义:
@property(nonatomic,retain) BMKLocationService* _locService;


ViewController.m:
#import "BMapKit.h"

@implementation ViewController

@synthesize _locService;

- (void)viewDidLoad{
    [super viewDidLoad];
    
    username.delegate = self;
    
    //初始化BMKLocationService
    _locService = [[BMKLocationService alloc]init];
    _locService.delegate = self;
    //启动LocationService
    [_locService startUserLocationService];
}

-(void) viewDidUnload{
    [LogUtil d:@"viewDidUnload"];
    [_locService stopUserLocationService];
}

//实现相关delegate 处理位置信息更新
//处理方向变更信息
- (void)didUpdateUserHeading:(BMKUserLocation *)userLocation{
    NSLog(@"heading is %@",userLocation.heading);
}
//处理位置坐标更新
- (void)didUpdateUserLocation:(BMKUserLocation *)userLocation{
    NSLog(@"lat:%f----lng:%f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);
}

@end

  • 大小: 17 KB
  • 大小: 34.8 KB
  • 大小: 25.4 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics