iOS 百度地图
来源:互联网 发布:电影院订票软件 编辑:程序博客网 时间:2024/05/16 09:16
百度地图详解地址
http://bbs.lbsyun.baidu.com/forum.php?mod=viewthread&tid=3621&extra=page%3D1
1.下载百度官方最新SDK 申请Key值(iOS申请Key值时需要Bundle Identifier)打开工程 - General -Identity - Bundle Identifier (注意Bundle Identifier内容全要,包括灰色部分,最好手写,不要复制)
2.导入inc文件夹
3.导入mapapi.bundle
4.导入第三方库,百度知道自已查去
5.导入静态库 libbaidumapapi.a(详细查到提供网址,里面有,很详细)
6.将任意一个.m后缀的文件改为.mm
7.//AppDelegate中引入头文件
#import "BMapKit.h"
定义属性
@property (nonatomic,strong)BMKMapManager *mapManager;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
_mapManager = [[BMKMapManageralloc]init];
BOOL ret = [_mapManagerstart:@"oq5tD9nMinGsU1bG4pOqMBQ7"generalDelegate:nil];
if (!ret) {
NSLog(@"manager start failed!");
}
returnYES;
}
8.//viewController里code
#import "ViewController.h"
#import "BMapKit.h"
@interface ViewController : UIViewController<BMKMapViewDelegate, BMKLocationServiceDelegate>
@property (strong, nonatomic)BMKMapView *mapView;
@property (strong, nonatomic) BMKLocationService *locService;
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
_locService = [[BMKLocationService alloc]init];
[_locService startUserLocationService];
_mapView.showsUserLocation = NO;
_mapView.userTrackingMode = BMKUserTrackingModeFollow;
_mapView.showsUserLocation = YES;
_mapView.zoomLevel = 12;
_mapView.mapType = BMKMapTypeStandard;
[self.view addSubview:_mapView];
}
-(void)viewWillAppear:(BOOL)animated {
[superviewWillAppear:animated];
[_mapViewviewWillAppear];
_mapView.delegate =self;// 此处记得不用的时候需要置nil,否则影响内存的释放
_locService.delegate = self;
}
-(void)viewWillDisappear:(BOOL)animated {
[superviewWillDisappear:animated];
[_mapViewviewWillDisappear];
_mapView.delegate =nil;// 不用时,置nil
_locService.delegate = nil;
}
-(void)dealloc {
[_locService stopUserLocationService];
}
/**
*在地图View将要启动定位时,会调用此函数
*@param mapView 地图View
*/
- (void)willStartLocatingUser
{
NSLog(@"start locate");
}
/**
*用户方向更新后,会调用此函数
*@param userLocation 新的用户位置 地图上蓝色大头针的数据
*/
- (void)didUpdateUserHeading:(BMKUserLocation *)userLocation
{
[_mapView updateLocationData:userLocation];
NSLog(@"heading is %@",userLocation.heading);
}
/**
*用户位置更新后,会调用此函数
*@param userLocation 新的用户位置
*/
- (void)didUpdateUserLocation:(BMKUserLocation *)userLocation
{
NSLog(@"didUpdateUserLocation lat %f,long %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);
[_mapView updateLocationData:userLocation];
[_locService stopUserLocationService];
}
/**
*在地图View停止定位后,会调用此函数
*@param mapView 地图View
*/
- (void)didStopLocatingUser
{
NSLog(@"stop locate");
}
/**
*定位失败后,会调用此函数
*@param mapView 地图View
*@param error 错误号,参考CLError.h中定义的错误号
*/
- (void)didFailToLocateUserWithError:(NSError *)error
{
NSLog(@"location error");
}
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
{
if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
BMKPinAnnotationView *newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];
newAnnotationView.pinColor = BMKPinAnnotationColorPurple;
newAnnotationView.animatesDrop = YES;// 设置该标注点动画显示
return newAnnotationView;
}
return nil;
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
//最后注意两点
9、自iOS SDK v2.5.0起,为了对iOS8的定位能力做兼容,做了相应的修改,开发者在使用过程中注意事项如下:需要在info.plist里添加(以下二选一,两个都添加默认使用NSLocationWhenInUseUsageDescription):
NSLocationWhenInUseUsageDescription ,允许在前台使用时获取GPS的描述
NSLocationAlwaysUsageDescription ,允许永久使用GPS的描述
10、在使用Xcode6进行SDK开发过程中,需要在info.plist中添加:Bundle display name ,且其值不能为空(Xcode6新建的项目没有此配置,若没有会造成manager start failed)
- iOS -- 百度地图API
- IOS开发百度地图
- iOS百度地图自定义
- iOS百度地图
- IOS百度地图开发
- iOS百度地图定位
- iOS 百度地图
- iOS百度地图使用
- IOS 百度地图
- IOS百度地图
- iOS- 集成百度地图
- iOS 百度地图
- iOS开发 - 百度地图
- iOS 百度地图
- iOS 百度地图
- IOS 百度地图API
- iOS百度地图 Demo
- iOS 开发 百度地图
- EA经典入门教程
- 国内外ACM在线判断题库网站大全
- 嵌入式平台上基于VS2005 WINCE6.0的SQLITE数据库应用
- HDU-Red and Black- 走方砖
- Android常用异步请求AsyncTask的美中不足之处
- iOS 百度地图
- 字节格式化
- 网络状态判断,如果没有连接网络启动网络设置界面
- 怎样快速成为某个领域的“专家”?
- GameObject的Active与InActive activeSelf, activeInHierarchy, SetActiveRecursively
- android开发中的一些触摸事件
- windwos核心编程读书笔记5——线程(5)用户态线程同步
- Android Shape图形
- 【BZOJ 1063】 [Noi2008]道路设计