百度地圖集成_集成SDK和基本功能實現

1.百度地圖導入項目中。。。。


1.注冊百度地圖,成為其開發者

注冊百度地圖開發者

2.創建應用:申請獲得密匙

創建應用獲得密匙

3.下載相關Demo

下載相關Demo

4.打開對應的demo,把BoundleId替換成注冊的密匙,然后再把對應的key替換AppDelegate中的輸入你的key,之后運行Dem哦,成功


自己項目中集成為:

在自己項目中集成

按照其中的手動配置.framework形式開發包要求做即可,如此大功告成(其中的要把任意一個文件變為.mm文件,不這樣做也是可以的(Xcode8))


如何集成地圖基本功能:

首先在AppDelegate中程序一起動打開百度地圖代碼如下:


- (BOOL)application:(UIApplication *)application

didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {? ? ? // 要使用百度地圖,請先啟動BaiduMapManager

_mapManager = [[BMKMapManager alloc]init];

// 如果要關注網絡及授權驗證事件,請設定? ? generalDelegate參數

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個方法要遵循BMKGeneralDelegate,實現才有用的

/**

*返回網絡錯誤

*@param iError 錯誤號

*/

- (void)onGetNetworkState:(int)iError {

if (iError) {

NSLog(@"error =%d",iError);

mAlertView(@"提示", @"聯網失敗");

}else {

NSLog(@"聯網成功");

}

}

/**

*返回授權驗證錯誤

*@param iError 錯誤號 : 為0時驗證通過,具體參加BMKPermissionCheckResultCode

*/

- (void)onGetPermissionState:(int)iError {

if (iError) {

mAlertView(@"提示", @"授權失敗");

NSLog(@"error =%d",iError);

}else {

mAlertView(@"提示", @"授權成功");

NSLog(@"授權成功");

}

}

在需要集成的VC中,

1.首先寫入下面的代碼(為了防止內存無法釋放的問題)

-(void)viewWillAppear:(BOOL)animated {

[self.mapView viewWillAppear];

self.mapView.delegate = self; // 此處記得不用的時候需要置nil,否則影響內存的釋放

[BMKMapView enableCustomMapStyle:self.isAutoMap];

}

-(void)viewWillDisappear:(BOOL)animated {

[BMKMapView enableCustomMapStyle:NO];//關閉個性化地圖

[self.mapView viewWillDisappear];

self.mapView.delegate = nil; // 不用時,置nil

}

-(void)dealloc {

if (_mapView) {

_mapView =nil;

}

}

2.MapView中如何想更改地圖的展示效果,可以導入對應的文件配置,寫入以下代碼

+ (void)initialize {

// 設置必須在BMKMapView初始化之前(會影響所有地圖示例)

NSString *path =[[NSBundle mainBundle] pathForResource:@"custom_config_黑夜" ofType:@""];

[BMKMapView customMapStyle:path];

}

在需要改變屬性的地方調用

[BMKMapView enableCustomMapStyle:self.isAutoMap];

其中self.isAutoMap為no時,是正常模式,為yes為自定義的某種模式

3.實現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");

}

附上: ? ? ?本人項目地址:

附上: ? ?2.百度地圖定位篇

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容