1.百度地圖導(dǎo)入項(xiàng)目中。。反番。。
1.注冊(cè)百度地圖叉钥,成為其開發(fā)者
2.創(chuàng)建應(yīng)用:申請(qǐng)獲得密匙
3.下載相關(guān)Demo
4.打開對(duì)應(yīng)的demo罢缸,把BoundleId替換成注冊(cè)的密匙,然后再把對(duì)應(yīng)的key替換AppDelegate中的輸入你的key投队,之后運(yùn)行Dem哦枫疆,成功
自己項(xiàng)目中集成為:
按照其中的手動(dòng)配置.framework形式開發(fā)包要求做即可,如此大功告成(其中的要把任意一個(gè)文件變?yōu)?mm文件敷鸦,不這樣做也是可以的(Xcode8))
如何集成地圖基本功能:
首先在AppDelegate中程序一起動(dòng)打開百度地圖代碼如下:
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {? ? ? // 要使用百度地圖息楔,請(qǐng)先啟動(dòng)BaiduMapManager
_mapManager = [[BMKMapManager alloc]init];
// 如果要關(guān)注網(wǎng)絡(luò)及授權(quán)驗(yàn)證事件,請(qǐng)?jiān)O(shè)定? ? generalDelegate參數(shù)
BOOL ret = [_mapManager start:@"替換成您的key"? generalDelegate:nil];
if (!ret) {
NSLog(@"manager start failed!");
}
// Add the navigation controller's view to the window and display.
self.window.frame =[UIScreen mainScreen].bounds;
UINavigationController *nav =[[UINavigationController alloc]initWithRootViewController:[[BMKMainListViewController alloc] init]];
self.window.rootViewController =nav;
[self.window makeKeyAndVisible];
return YES;
}
其中下面的2個(gè)方法要遵循BMKGeneralDelegate扒披,實(shí)現(xiàn)才有用的
/**
*返回網(wǎng)絡(luò)錯(cuò)誤
*@param iError 錯(cuò)誤號(hào)
*/
- (void)onGetNetworkState:(int)iError {
if (iError) {
NSLog(@"error =%d",iError);
mAlertView(@"提示", @"聯(lián)網(wǎng)失敗");
}else {
NSLog(@"聯(lián)網(wǎng)成功");
}
}
/**
*返回授權(quán)驗(yàn)證錯(cuò)誤
*@param iError 錯(cuò)誤號(hào) : 為0時(shí)驗(yàn)證通過值依,具體參加BMKPermissionCheckResultCode
*/
- (void)onGetPermissionState:(int)iError {
if (iError) {
mAlertView(@"提示", @"授權(quán)失敗");
NSLog(@"error =%d",iError);
}else {
mAlertView(@"提示", @"授權(quán)成功");
NSLog(@"授權(quán)成功");
}
}
在需要集成的VC中,
1.首先寫入下面的代碼(為了防止內(nèi)存無法釋放的問題)
-(void)viewWillAppear:(BOOL)animated {
[self.mapView viewWillAppear];
self.mapView.delegate = self; // 此處記得不用的時(shí)候需要置nil碟案,否則影響內(nèi)存的釋放
[BMKMapView enableCustomMapStyle:self.isAutoMap];
}
-(void)viewWillDisappear:(BOOL)animated {
[BMKMapView enableCustomMapStyle:NO];//關(guān)閉個(gè)性化地圖
[self.mapView viewWillDisappear];
self.mapView.delegate = nil; // 不用時(shí)愿险,置nil
}
-(void)dealloc {
if (_mapView) {
_mapView =nil;
}
}
2.MapView中如何想更改地圖的展示效果,可以導(dǎo)入對(duì)應(yīng)的文件配置价说,寫入以下代碼
+ (void)initialize {
// 設(shè)置必須在BMKMapView初始化之前(會(huì)影響所有地圖示例)
NSString *path =[[NSBundle mainBundle] pathForResource:@"custom_config_黑夜" ofType:@""];
[BMKMapView customMapStyle:path];
}
在需要改變屬性的地方調(diào)用
[BMKMapView enableCustomMapStyle:self.isAutoMap];
其中self.isAutoMap為no時(shí)辆亏,是正常模式,為yes為自定義的某種模式
3.實(shí)現(xiàn)BMKMapViewDelegate的以下代理方法:
- (void)mapViewDidFinishLoading:(BMKMapView *)mapView {
//? ? UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"BMKMapView控件初始化完成" delegate:nil cancelButtonTitle:@"知道了" otherButtonTitles: nil];
//? ? [alert show];
//? ? alert = nil;
}
- (void)mapView:(BMKMapView *)mapView onClickedMapBlank:(CLLocationCoordinate2D)coordinate {
NSLog(@"map view: click blank");
}
- (void)mapview:(BMKMapView *)mapView onDoubleClick:(CLLocationCoordinate2D)coordinate {
NSLog(@"map view: double click");
}
附上: ? ? ?本人項(xiàng)目地址:
附上: ? ?2.百度地圖定位篇