iOS 百度地图SDK使用
2015-09-21 10:01
387 查看
1、配置开发环境,请参考官网http://developer.baidu.com/map/index.php?title=iossdk/guide/buildproject
2、需要地图的定位功能在后台长期运行的话就要在Info.plist->Information Property List->添加key = NSLocationAlwaysUsageDescription,Value = NSLocationWhenInUseUsageDescription;key = NSLocationWhenInUseUsageDescription,Value = NSLocationWhenInUseUsageDescription。
3、定位功能,要加上代理BMKLocationServiceDelegate
4、正地理编码(地址->经纬度)、反地理编码(经纬度->地址),添加BMKGeoCodeSearchDelegate,BMKLocationServiceDelegate代理
5、正常地图显示、大头针显示、轨迹显示等,可以参考百度SDK官方文档http://developer.baidu.com/map/index.php?title=iossdk/guide/basicmap
添加折线覆盖物
2、需要地图的定位功能在后台长期运行的话就要在Info.plist->Information Property List->添加key = NSLocationAlwaysUsageDescription,Value = NSLocationWhenInUseUsageDescription;key = NSLocationWhenInUseUsageDescription,Value = NSLocationWhenInUseUsageDescription。
3、定位功能,要加上代理BMKLocationServiceDelegate
-(void)viewDidLoad { //设置定位精确度,默认:kCLLocationAccuracyBest [BMKLocationServicesetLocationDesiredAccuracy:kCLLocationAccuracyNearestTenMeters]; //指定最小距离更新(米),默认:kCLDistanceFilterNone [BMKLocationServicesetLocationDistanceFilter:100.f]; //初始化BMKLocationService _locService = [[BMKLocationService alloc]init]; _locService.delegate = self; //启动定位功能 [_locService startUserLocationService]; //[_locService stopUserLocationService];//停止定位功能 } //实现相关delegate 处理位置信息更新 //处理方向变更信息 - (void)didUpdateUserHeading:(BMKUserLocation *)userLocation { //NSLog(@"heading is %@",userLocation.heading); } //处理位置坐标更新 - (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation { //NSLog(@"纬度 = %f,经度 = %f,高度 = %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude,userLocation.location.altitude); //展示定位信息 //普通态 //以下_mapView为BMKMapView对象 _mapView.showsUserLocation = YES;//显示定位图层 [_mapView updateLocationData:userLocation]; }
4、正地理编码(地址->经纬度)、反地理编码(经纬度->地址),添加BMKGeoCodeSearchDelegate,BMKLocationServiceDelegate代理
- (void)viewDidLoad { [super viewDidLoad]; //反地理编码 reverseGeoCodeOption= [[BMKReverseGeoCodeOption alloc] init]; LocSearch = [[BMKGeoCodeSearch alloc]init]; LocSearch.delegate = self; //正地理编码 geoCodeSearchOption = [[BMKGeoCodeSearchOption alloc]init]; geoCodeSearchOption.address = @"这里填地址"; [LocSearch geoCode:geoCodeSearchOption]; } //正地理编码代理 - (void)onGetGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error{ if (error == BMK_SEARCH_NO_ERROR) { //在此处理正常结果 MapLatitude = result.location.latitude;//纬度 MapLongitude = result.location.longitude;//经度 MapAddressStr = result.address;//地址 } else { NSLog(@"抱歉,未找到结果"); UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:@"抱歉,未找到结果!" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil]; [alert show]; } } //反地理编码代理 - (void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error { NSLog(@"地址为:%@%@%@%@%@",result.addressDetail.province,result.addressDetail.city,result.addressDetail.district,result.addressDetail.streetName,result.addressDetail.streetNumber); }
5、正常地图显示、大头针显示、轨迹显示等,可以参考百度SDK官方文档http://developer.baidu.com/map/index.php?title=iossdk/guide/basicmap
添加折线覆盖物
CLLocationCoordinate2D coors[MapArray.count]; for (int i = 0; i<MapArray.count; i++) { NSLog(@"%f,%f",[[[MapArray objectAtIndex:i] objectForKey:@"Latitude"] floatValue], [[[MapArray objectAtIndex:i] objectForKey:@"Longitude"] floatValue]); CLLocationCoordinate2D annotationCoord = CLLocationCoordinate2DMake([[[MapArray objectAtIndex:i] objectForKey:@"Latitude"] floatValue], [[[MapArray objectAtIndex:i] objectForKey:@"Longitude"] floatValue]); coors[i] = annotationCoord; } polyline1 = [BMKPolyline polylineWithCoordinates:coors count:MapArray.count]; [_mapView addOverlay:polyline1];
- (BMKOverlayView *)mapView:(BMKMapView *)mapView viewForOverlay:(id <BMKOverlay>)overlay{ if ([overlay isKindOfClass:[BMKPolyline class]]){ BMKPolylineView* polylineView = [[BMKPolylineView alloc] initWithOverlay:overlay]; polylineView.strokeColor = [[UIColor purpleColor] colorWithAlphaComponent:1]; polylineView.lineWidth = 5.0; return polylineView; } return nil; }
相关文章推荐
- iOS开发脚踏实地学习day11-导航控制器
- IOS工具篇
- IOS汇总
- IOS开发测试之单元测试一
- iOS 技术分享5
- iOS之旅--使用控件的属性frame、center、bounds
- iOS开发中的几个手势操作实例分享
- Masonry介绍与使用实践:快速上手Autolayout
- IOS9.0中hash值的bug与解决方案
- iOS 不要使用tag传递TableViewCell的indexPath值
- Nagios检测工具介绍
- iOS 汉字转拼音
- IOS 多行多列加载ImageView
- IOS中NSUserDefaults的用法
- IOS版本回退操作教程
- 第一课: iOS入门
- iOS小文件的下载方式
- ios 开发小记 (三)
- iOS-新浪微博开发-26-下拉刷新
- ios-新浪微博开发-25-字典转模型(2)