ios 百度地图指定区域_iOS开发(第三方使用)——百度地图的简单使用(定位与当前位置的显示)...

使用cocoapods导入 pod ‘BaiduMapKit’

在plist添加NSLocationAlwaysUsageDescription

去百度地图开发者中心注册帐号,并创建项目,拿到AK的值

在工程的AppDelegate.m导入头文件BaiduMapAPI_Base/BMKBaseComponent.h、BaiduMapAPI_Map/BMKMapComponent.h

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //百度地图 BMKMapManager *_mapManager = [[BMKMapManager alloc]init]; BOOL ret = [_mapManager start:@"你的AK" generalDelegate:self]; if (!ret) { NSLog(@"manager start failed!"); } return YES; }

在控制器里面导入头文件BaiduMapAPI_Location/BMKLocationService.h、BaiduMapAPI_Map/BMKMapComponent.h并设置代理BMKLocationServiceDelegate,BMKMapViewDelegate

`- (void)viewDidLoad {

[super viewDidLoad];

//初始化BMKLocationService

_locService = [[BMKLocationService alloc]init];

_locService.delegate = self;

//启动LocationService

[_locService startUserLocationService];

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

_mapView.delegate = self; // 此处记得不用的时候需要置nil,否则影响内存的释放

_mapView.mapType = BMKMapTypeStandard;

[_mapView setZoomLevel:19.0];

[self.view addSubview:_mapView];

}

(void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation

{

BMKCoordinateRegion region;

region.center.latitude = userLocation.location.coordinate.latitude;

region.center.longitude = userLocation.location.coordinate.longitude;

region.span.latitudeDelta = 0.2;

region.span.longitudeDelta = 0.2;

if (_mapView)

{

_mapView.region = region;

}

[_mapView setZoomLevel:19.0];

[_locService stopUserLocationService];//定位完成停止位置更新

//添加当前位置的标注

CLLocationCoordinate2D coord;

coord.latitude = userLocation.location.coordinate.latitude;

coord.longitude = userLocation.location.coordinate.longitude;

BMKPointAnnotation *_pointAnnotation = [[BMKPointAnnotation alloc] init];

_pointAnnotation.coordinate = coord;

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

pt=(CLLocationCoordinate2D){coord.latitude,coord.longitude};

dispatch_async(dispatch_get_main_queue(), ^{

[_mapView removeOverlays:_mapView.overlays];

[_mapView setCenterCoordinate:coord animated:true];

[_mapView addAnnotation:_pointAnnotation];

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值