您的位置:首页 > 移动开发 > IOS开发

iOS百度地图 定位,获取当前经纬度

2017-08-22 14:39 525 查看
百度地图定位

.集成百度地图SDK  http://blog.csdn.net/chuan403082010/article/details/77478182

.开始定位 官网链接: http://lbsyun.baidu.com/index.php?title=iossdk/guide/location

#import "ViewController.h"
#import <BaiduMapAPI_Location/BMKLocationService.h>
@interface ViewController ()<BMKLocationServiceDelegate>

@property (strong, nonatomic) BMKLocationService * locService;//定位
@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
_locService = [[BMKLocationService alloc]init];
_locService.delegate = self;
[_locService startUserLocationService];

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

/**
*用户方向更新后,会调用此函数
*@param userLocation 新的用户位置
*/
- (void)didUpdateUserHeading:(BMKUserLocation *)userLocation
{

NSLog(@"方向更新%f  %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);
}

/**
*用户位置更新后,会调用此函数
*@param userLocation 新的用户位置
*/
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation{
NSLog(@"位置更新%f  %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);
}

/**
*定位失败后,会调用此函数
*@param error 错误号
*/
- (void)didFailToLocateUserWithError:(NSError *)error{
NSLog(@"定位失败%@",error);
}

@end


在info.plist里 设置开启定位权限 

Privacy - Location When In Use Usage Description  或Privacy - Location Always Usage Description

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: