如何快速集成百度地圖:
注冊百度開發(fā)者帳號=》創(chuàng)建應(yīng)用=》下載SDK=》集成開發(fā)=》測試應(yīng)用=》發(fā)布應(yīng)用
1、注冊百度開發(fā)者賬號
百度賬號注冊地址:https://passport.baidu.com/v2/?reg?Type=1&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F,如果你已經(jīng)有百度賬號可以跳過這步肋演。
登錄后恶复,進(jìn)入開發(fā)者中心普监,注冊成為百度開發(fā)者阀捅,http://developer.baidu.com/user/info?u=http://lbsyun.baidu.com/apiconsole/key?from=developer拂铡,填寫好個人信息陨溅,提交终惑。
2、創(chuàng)建新應(yīng)用
在使用百度地圖SDK之前需要先獲取百度地圖移動版開發(fā)密鑰门扇。
百度地圖iOS SDK開發(fā)密鑰的申請地址為:http://lbsyun.baidu.com/apiconsole/key雹有。
點(diǎn)擊以上網(wǎng)址進(jìn)入API控制臺,選擇創(chuàng)建應(yīng)用臼寄,填寫應(yīng)用信息:
確認(rèn)后創(chuàng)建完成霸奕,可以在我的應(yīng)用終看到應(yīng)用的ak:
3、下載IOS SDK
百度地圖iOS SDK的下載地址:http://developer.baidu.com/map/sdkiosdev-download.htm
進(jìn)入后可以下載全部功能吉拳,也可以根據(jù)自己需要選擇模塊選擇下載:
4质帅、集成開發(fā)
1)新建一個工程
2)添加百度SDK和靜態(tài)庫
解壓下載后的iOS SDK壓縮包將壓縮包內(nèi)的inc文件夾和mapapi.bundle文件拷貝到工程目錄下。
接下來根據(jù)模擬器和真機(jī)兩種環(huán)境選擇使用靜態(tài)庫文件:
如果用的真機(jī)留攒,就導(dǎo)入iphoneos文件夾內(nèi)的libbaidumapapi.a文件到工程煤惩,如果用的模擬器,就導(dǎo)入iphonesimulator文件夾內(nèi)的libbaidumapapi.a文件到工程炼邀。
引入如下圖所示的framework:
3)導(dǎo)入頭文件魄揉,初始化并啟動百度地圖
首先在工程的.pch文件中導(dǎo)入頭文件,并宏定義APPKEY:
1.#import"BMapKit.h"
2.#define?APPKEY?@"9D6E6FFvXskzZge2GuwXWsRi"
在Appdelegate.h中添加代碼如下拭宁,必須property? BMKMapManager洛退,不然無法啟動地圖服務(wù):
_mapManager?=?[[BMKMapManageralloc]?init?];
BOOLret?=?[_mapManagerstart:APPKEYgeneralDelegate:nil];
if(!ret)?{
NSLog(@"啟動失敗");
}
4)創(chuàng)建BMKMapView瓣俯,顯示百度地圖視圖
#import<UIKit/UIKit.h>
@interfaceBaseMapViewController?:?UIViewController
@property?(nonatomic,?strong)?BMKMapView?*mapView;
@end
在.m文件
-?(void)viewDidLoad
{
?//這里的frame請根據(jù)手機(jī)分辨率動態(tài)設(shè)置???? self.mapView.frame?=?CGRectMake(0,?0,?320,?460-44);
self.mapView.delegate?=?self;
[self.viewaddSubview:self.mapView];
}
-?(void)viewWillAppear:(BOOL)animated
{
[_mapViewviewWillAppear];
_mapView.delegate?=?self;//?此處記得不用的時(shí)候需要置nil,否則影響內(nèi)存的釋放
}
-?(void)viewWillDisappear:(BOOL)animated
{
[_mapViewviewWillDisappear];
_mapView.delegate?=?nil;//?不用時(shí)兵怯,置nil
}
5)更改地圖顯示方式
switch(index)?{
case0:{
//設(shè)置地圖顯示類型彩匕,有四種標(biāo)準(zhǔn)地圖、實(shí)時(shí)路況摇零、衛(wèi)星地圖推掸、同時(shí)打開實(shí)時(shí)路況和衛(wèi)星地圖
self.mapView.mapType?=?BMKMapTypeStandard;
break;
}
case1:{
self.mapView.mapType?=?BMKMapTypeTrafficOn;
break;
}
case2:{
self.mapView.mapType?=?BMKMapTypeSatellite;
break;
}
default:{
self.mapView.mapType?=?BMKMapTypeTrafficAndSatellite;
break;
}
}
6)添加地圖標(biāo)注
首先設(shè)置標(biāo)注的基本屬性
在.h文件描述一下
@property?(nonatomic,?strong)?BMKPointAnnotation?*annotation;
在.m文件
self.annotation?=?[BMKPointAnnotationnew];
CLLocationCoordinate2Dcoor;
coor.latitude?=?39.911447;
coor.longitude?=?116.406026;
//設(shè)置標(biāo)注的坐標(biāo)
self.annotation.coordinate?=?coor;
//標(biāo)題
self.annotation.title?=?@"北京";
//副標(biāo)題
self.annotation.subtitle?=?@"這個annotation可以拖拽";
[self.mapViewaddAnnotation:self.annotation];
詳細(xì)設(shè)置標(biāo)注,以下方法是SDK自帶的驻仅,方法內(nèi)容需要自己寫
-?(BMKAnnotationView?*)mapView:(BMKMapView?*)mapViewviewForAnnotation:(id)annotation{
if([annotation?isKindOfClass:[BMKPointAnnotationclass]])?{
BMKPinAnnotationView?*newAnnotationView?=?[[BMKPinAnnotationViewalloc]initWithAnnotation:annotationreuseIdentifier:@"myAnnotation"];
newAnnotationView.pinColor?=?BMKPinAnnotationColorGreen;
//動畫效果
newAnnotationView.animatesDrop?=?YES;
//可以拖拽
newAnnotationView.draggable?=?YES;
//3D效果
newAnnotationView.enabled3D?=?YES;
returnnewAnnotationView;
}
returnnil;
}
在不用標(biāo)注的時(shí)候谅畅,把它從視圖上移除
-?(void)viewDidDisappear:(BOOL)animated
{
[superviewDidDisappear:animated];
if(self.annotation!=nil)?{
[self.mapViewremoveAnnotation:self.annotation];
}
}
7)POI興趣點(diǎn)檢索
百度地圖SDK提供了三種POI搜索(周邊、區(qū)域噪服、城市內(nèi)搜索)毡泻,搜索方式都類似,下面以周邊搜索做個示例粘优。
在.h文件:
#import"BaseMapViewController.h"
@interfacePoiViewController?:?BaseMapViewController
@property?(nonatomic,?strong)?BMKPoiSearch?*searcher;
@end
在.m文件
-?(void)viewDidLoad
{
[superviewDidLoad];
self.searcher?=?[BMKPoiSearchnew];
self.searcher.delegate?=?self;
//搜索周邊
BMKNearbySearchOption?*option?=?[BMKNearbySearchOptionnew];
//搜索周邊時(shí)的中心點(diǎn)坐標(biāo)
option.location?=?CLLocationCoordinate2DMake(39.911447,?116.406026);
//搜索的關(guān)鍵字
option.keyword?=?@"肯德基";
BOOLflag?=?[self.searcherpoiSearchNearBy:option];
if(!flag)?{
NSLog(@"周邊檢索失敗");
}
}
搜索到結(jié)果之后的代理方法
-?(void)onGetPoiResult:(BMKPoiSearch?*)searcher?result:(BMKPoiResult?*)poiResulterrorCode:(BMKSearchErrorCode)errorCode{
//在添加標(biāo)注前把以前的標(biāo)注都移除掉
NSMutableArray?*poiAnnotations?=?[NSMutableArrayarrayWithCapacity:poiResult.poiInfoList.count];
[self.mapViewremoveAnnotations:poiAnnotations];
if(errorCode?==?BMK_SEARCH_NO_ERROR)?{
NSLog(@"找到結(jié)果");
for(inti?=?0;?i
BMKPoiInfo?*info?=?[poiResult.poiInfoListobjectAtIndex:i];
BMKPointAnnotation?*pointAnnotation?=?[BMKPointAnnotationnew];
pointAnnotation.coordinate?=?info.pt;
pointAnnotation.title?=?info.name;
pointAnnotation.subtitle?=?[NSStringstringWithFormat:@"%@%@",info.city,info.address];
[poiAnnotationsaddObject:pointAnnotation];
//設(shè)置第一個搜索到的興趣點(diǎn)為中心點(diǎn)
if(i==0)?{
self.mapView.centerCoordinate?=?info.pt;
}
}
[self.mapViewaddAnnotations:poiAnnotations];
}elseif?(errorCode?==?BMK_SEARCH_AMBIGUOUS_KEYWORD){
NSLog(@"起始點(diǎn)有歧義仇味,有相同名字的別的城市:%@",poiResult.cityList);
}else{
NSLog(@"未找到結(jié)果");
}
}
-?(void)viewWillDisappear:(BOOL)animated
{
[superviewWillDisappear:animated];
NSArray?*array?=?[NSArrayarrayWithArray:self.mapView.annotations];
[self.mapViewremoveAnnotations:array];
self.searcher.delegate?=?nil;//不用的時(shí)候代理取消
}
8)路徑規(guī)劃
路徑規(guī)劃有三種類型(公交、駕車雹顺、步行)丹墨,使用方式都類似,下面以駕車做個示例嬉愧。
在.h文件
#import"BaseMapViewController.h"
@interfaceWayPointViewController?:?BaseMapViewController
@property?(nonatomic,?strong)?BMKRouteSearch?*routeSearch;
@end
在.m文件
-?(void)viewDidLoad
{
[superviewDidLoad];
self.routeSearch?=?[BMKRouteSearchnew];
self.routeSearch.delegate?=?self;
//線路起點(diǎn)信息
BMKPlanNode?*start?=?[BMKPlanNodenew];
start.name?=?@"天安門";
start.cityName?=?@"北京市";
//終點(diǎn)信息
BMKPlanNode?*end?=?[BMKPlanNodenew];
end.name?=?@"百度大廈";
end.cityName?=?@"北京市";
//途經(jīng)點(diǎn)信息
BMKPlanNode?*wayPoint1?=?[BMKPlanNodenew];
wayPoint1.cityName?=?@"北京市";
wayPoint1.name?=?@"東直門";
NSMutableArray?*array?=?[NSMutableArraynew];
[arrayaddObject:wayPoint1];
//駕車查詢
BMKDrivingRoutePlanOption?*drivePlan?=?[[BMKDrivingRoutePlanOptionalloc]init];
drivePlan.from?=?start;
drivePlan.to?=?end;
drivePlan.wayPointsArray?=?array;
BOOLflag?=?[self.routeSearchdrivingSearch:drivePlan];
if(!flag)?{
NSLog(@"公交檢索發(fā)送失敗");
}
}
//根據(jù)搜索返回的結(jié)果繪制折線
-?(void)onGetDrivingRouteResult:(BMKRouteSearch?*)searcher?result:(BMKDrivingRouteResult?*)result?errorCode:(BMKSearchErrorCode)error
{
//移除地圖的標(biāo)注和覆蓋物
NSArray?*array?=?[NSArrayarrayWithArray:self.mapView.annotations];
[self.mapViewremoveAnnotations:array];
array?=?[NSArrayarrayWithArray:self.mapView.overlays];
[self.mapViewremoveAnnotations:array];
if(error?==?BMK_SEARCH_NO_ERROR)?{
BMKDrivingRouteLine?*plan?=?[result.routesobjectAtIndex:0];
intsize?=?plan.steps.count;
//軌跡點(diǎn)
CLLocationCoordinate2DpolylineCoords[size];
for(inti=0?;i
BMKDrivingStep?*drivingStep?=?[plan.stepsobjectAtIndex:i];
//添加annotation節(jié)點(diǎn)
BMKPointAnnotation*?item?=?[BMKPointAnnotationnew];
item.coordinate?=?drivingStep.entrace.location;
polylineCoords[i]=?drivingStep.entrace.location;
item.title?=?drivingStep.entraceInstruction;
[self.mapViewaddAnnotation:item];
//?添加起點(diǎn)標(biāo)注
if(i==0)?{
item.title?=?@"起點(diǎn)";
[self.mapViewselectAnnotation:itemanimated:YES];
}
//?添加起點(diǎn)標(biāo)注
if(i==size-1){
item.title?=?@"終點(diǎn)";
}
}
//繪制折線
BMKPolyline*?polyLine?=?[BMKPolylinepolylineWithCoordinates:polylineCoordscount:size];
[self.mapViewaddOverlay:polyLine];
}
}
//定義折線樣式
-?(BMKOverlayView*)mapView:(BMKMapView?*)map?viewForOverlay:(id)overlay
{
if([overlay?isKindOfClass:[BMKPolylineclass]])?{
BMKPolylineView*?polylineView?=?[[BMKPolylineViewalloc]?initWithOverlay:overlay];
polylineView.fillColor?=?[UIColorblackColor];
polylineView.strokeColor?=?[UIColorblueColor];
polylineView.lineWidth?=?6.0f;
returnpolylineView;
}
returnnil;
}
-?(void)viewDidDisappear:(BOOL)animated
{
[superviewDidDisappear:animated];
NSArray?*array?=?[NSArrayarrayWithArray:self.mapView.annotations];
[self.mapViewremoveAnnotations:array];
array?=?[NSArrayarrayWithArray:self.mapView.overlays];
[self.mapViewremoveAnnotations:array];
self.routeSearch.delegate?=?nil;//不用的時(shí)候代理取消
}
9)地圖定位
在.h文件
#import"BaseMapViewController.h"
@interfaceUserLocationViewController?:?BaseMapViewController
@property?(nonatomic,?strong)BMKLocationService?*localService;
@end
在.m文件
self.localService?=?[BMKLocationServicenew];
self.localService.delegate?=?self;
[self.localServicestartUserLocationService];
//改變地圖定位樣式的時(shí)候必須先關(guān)閉圖層贩挣,改變樣式后再打開
//關(guān)閉顯示的定位圖層
self.mapView?.showsUserLocation?=?NO;
switch(index)?{
case0:{
//三種定位模式:普通、跟隨没酣、羅盤
self.mapView.userTrackingMode?=?BMKUserTrackingModeNone;
break;
}
case1:{
self.mapView.userTrackingMode?=?BMKUserTrackingModeFollowWithHeading;
break;
}
default:{
self.mapView.userTrackingMode?=?BMKUserTrackingModeFollow;
break;
}
}
//打開顯示的定位圖層
self.mapView?.showsUserLocation?=?YES;
10)短串分享
短串分享是在用戶搜索查詢后得到的每一個地理位置結(jié)果會對應(yīng)一個短連接王财,用戶可以通過短信等方式分享給別人。當(dāng)用戶受到分享的短串后裕便,點(diǎn)擊短串可以打開百度地圖客戶端或手機(jī)瀏覽器進(jìn)行查看绒净。
定義幾個屬性用來存放搜素的數(shù)據(jù)
//名稱
NSString*?geoName;
//地址
NSString*?addr;
//坐標(biāo)
CLLocationCoordinate2Dpt;
//短串
NSString*?shortUrl;
//分享字符串
NSString*?showmeg;
首先初始化對象,并發(fā)起一個搜索
self.shareSearch?=?[BMKShareURLSearchnew];
self.shareSearch.delegate?=?self;
self.poiSearch?=?[BMKPoiSearchnew];
self.poiSearch.delegate?=?self;
BMKNearbySearchOption?*option?=?[BMKNearbySearchOptionnew];
option.pageIndex?=?0;
option.pageCapacity?=?10;
option.location?=?CLLocationCoordinate2DMake(39.911447,?116.406026);
option.keyword?=?@"肯德基";
BOOLflag?=?[self.poiSearchpoiSearchNearBy:option];
if(!flag)?{
NSLog(@"周邊檢索失敗");
}
搜索成功后偿衰,處理數(shù)據(jù)挂疆,獲取要分享的url,發(fā)起分享
-?(void)onGetPoiResult:(BMKPoiSearch?*)searcher?result:(BMKPoiResult?*)poiResulterrorCode:(BMKSearchErrorCode)errorCode{
if(errorCode?==?BMK_SEARCH_NO_ERROR)?{
for(inti?=?0;?i
BMKPoiInfo?*info?=?[poiResult.poiInfoListobjectAtIndex:i];
BMKPointAnnotation?*pointAnnotation?=?[BMKPointAnnotationnew];
pointAnnotation.coordinate?=?info.pt;
pointAnnotation.title?=?info.name;
pointAnnotation.subtitle?=?[NSStringstringWithFormat:@"%@%@",info.city,info.address];
[poiAnnotationsaddObject:pointAnnotation];
if(i==0)?{
self.mapView.centerCoordinate?=?info.pt;
geoName?=?info.name;
addr?=?info.address;
pt?=?info.pt;
BMKPoiDetailShareURLOption?*option?=?[BMKPoiDetailShareURLOptionnew];
option.uid?=?info.uid;
BOOLflag?=?[self.shareSearchrequestPoiDetailShareURL:option];
if(!flag)?{
NSLog(@"詳情url檢索發(fā)送失敗");
}}}}}
處理分享的方法
-(void)onGetPoiDetailShareURLResult:(BMKShareURLSearch?*)searcher?result:(BMKShareURLResult?*)result?errorCode:(BMKSearchErrorCode)error
{
shortUrl?=?result.url;
if(error?==?BMK_SEARCH_NO_ERROR)
{
showmeg?=?[NSStringstringWithFormat:@"這里是:%@\r\n%@\r\n%@",geoName,addr,shortUrl];
UIAlertView?*myAlertView?=?[[UIAlertViewalloc]?initWithTitle:@"短串分享"message:showmegdelegate:selfcancelButtonTitle:nilotherButtonTitles:@"分享",@"取消",nil];
myAlertView.tag?=?1000;
[myAlertViewshow];
}}
判斷如果設(shè)備可以發(fā)送短信下翎,則發(fā)送分享
-?(void)alertView:(UIAlertView?*)alertViewclickedButtonAtIndex:(NSInteger)buttonIndex
{
if(alertView.tag?==1000?)
{
if(buttonIndex?==?0)
{
Class?messageClass?=?(NSClassFromString(@"MFMessageComposeViewController"));
if(messageClass?!=?nil)?{
if([messageClasscanSendText])?{
MFMessageComposeViewController?*picker?=?[[MFMessageComposeViewControlleralloc]?init];
picker.messageComposeDelegate?=?self;
picker.body?=?[NSStringstringWithFormat:@"%@",showmeg];
[selfpresentModalViewController:pickeranimated:YES];
}else{
UIAlertView?*myAlertView?=?[[UIAlertViewalloc]?initWithTitle:@"當(dāng)前設(shè)備無法發(fā)送短信"message:nildelegate:selfcancelButtonTitle:nilotherButtonTitles:@"確定",nil];
[myAlertViewshow];
}}}}}
11)調(diào)啟導(dǎo)航
調(diào)啟導(dǎo)航分為兩種:百度地圖客戶端和Web導(dǎo)航缤言。
首先要配置info.plist,自定義一個URL Scheme和APP綁定漏设,選擇工程Targets》Info》URL Types墨闲,點(diǎn)擊+號添加一個url type。
如圖所示:
下面開始編寫代碼郑口,
#defineMAPScheme?@"
baidumapsdk://mapsdk.baidu.com
"
@property?(nonatomic,?strong)BMKNaviPara?*para;
//判讀是否能打開百度地圖客戶端
-?(BOOL)canOpenBaiDuMap
{
return[[UIApplicationsharedApplication]?canOpenURL:[NSURLURLWithString:MAPScheme]];
}
-?(void)viewDidLoad
{
[superviewDidLoad];
self.para?=?[BMKNaviParanew];
BOOLflag?=?[selfcanOpenBaiDuMap];
if(flag)?{
//使用百度地圖客戶端導(dǎo)航
self.para.naviType?=?BMK_NAVI_TYPE_NATIVE;
//初始化終點(diǎn)節(jié)點(diǎn)
BMKPlanNode*?end?=?[BMKPlanNodenew];
//指定終點(diǎn)經(jīng)緯度
CLLocationCoordinate2D?coor2;
coor2.latitude?=?116.3956;
coor2.longitude?=?39.90868;
end.pt?=?coor2;
//指定終點(diǎn)名稱
end.name?=?@"北京市天安門";
//指定終點(diǎn)
self.para.endPoint?=?end;
//指定返回自定義scheme鸳碧,具體定義方法請參考常見問題
self.para.appScheme?=?MAPScheme;
//調(diào)啟百度地圖客戶端導(dǎo)航
[BMKNavigationopenBaiduMapNavigation:self.para];
}else{
//使用WEB導(dǎo)航
self.para.naviType?=?BMK_NAVI_TYPE_WEB;
//初始化起點(diǎn)節(jié)點(diǎn)
BMKPlanNode*?start?=?[BMKPlanNodenew];
//指定起點(diǎn)經(jīng)緯度
CLLocationCoordinate2D?coor1;
coor1.latitude?=?116.204;
coor1.longitude?=?39.90868;
start.pt?=?coor1;
//指定起點(diǎn)名稱
start.name?=?@"西直門";
//指定起點(diǎn)
self.para.startPoint?=?start;
//初始化終點(diǎn)節(jié)點(diǎn)
BMKPlanNode*?end?=?[BMKPlanNodenew];
CLLocationCoordinate2D?coor2;
coor2.latitude?=?116.3956;
coor2.longitude?=?39.90868;
end.pt?=?coor2;
self.para.endPoint?=?end;
//指定終點(diǎn)名稱
end.name?=?@"北京市天安門";
//指定調(diào)啟導(dǎo)航的app名稱
self.para.appName?=?@"BaiDuMap";
//調(diào)啟web導(dǎo)航
[BMKNavigationopenBaiduMapNavigation:self.para];
}
}
主要功能
實(shí)時(shí)路況:
衛(wèi)星地圖:
地圖標(biāo)注:
功能特色
興趣點(diǎn)搜索:
路徑規(guī)劃:
短串分享:
DEMO展示
部分測試DEMO展示:
#import"ShareUrlViewController.h"
#import
#import
@interfaceShareUrlViewController?()
{
//名稱
NSString*?geoName;
//地址
NSString*?addr;
//坐標(biāo)
CLLocationCoordinate2Dpt;
//短串
NSString*?shortUrl;
//分享字符串
NSString*?showmeg;
}
@end
@implementationShareUrlViewController
-?(BMKAnnotationView?*)mapView:(BMKMapView?*)mapViewviewForAnnotation:(id)annotation{
if([annotation?isKindOfClass:[BMKPointAnnotationclass]])?{
BMKPinAnnotationView?*newAnnotationView?=?[[BMKPinAnnotationViewalloc]initWithAnnotation:annotationreuseIdentifier:@"myAnnotation"];
newAnnotationView.pinColor?=?BMKPinAnnotationColorGreen;
//動畫效果
newAnnotationView.animatesDrop?=?YES;
//3D效果
newAnnotationView.enabled3D?=?YES;
//單擊彈出泡泡盾鳞,默認(rèn)是YES
//newAnnotationView.canShowCallout?=?YES;
returnnewAnnotationView;
}
returnnil;
}
-?(id)initWithNibName:(NSString?*)nibNameOrNil?bundle:(NSBundle?*)nibBundleOrNil
{
self?=?[superinitWithNibName:nibNameOrNilbundle:nibBundleOrNil];
if(self)?{
//?Custom?initialization
}
returnself;
}
-?(void)viewDidLoad
{
[superviewDidLoad];
self.shareSearch?=?[BMKShareURLSearchnew];
self.shareSearch.delegate?=?self;
self.poiSearch?=?[BMKPoiSearchnew];
self.poiSearch.delegate?=?self;
BMKNearbySearchOption?*option?=?[BMKNearbySearchOptionnew];
option.pageIndex?=?0;
option.pageCapacity?=?10;
option.location?=?CLLocationCoordinate2DMake(39.911447,?116.406026);
option.keyword?=?@"肯德基";
BOOLflag?=?[self.poiSearchpoiSearchNearBy:option];
if(!flag)?{
NSLog(@"周邊檢索失敗");
}
}
-?(void)onGetPoiResult:(BMKPoiSearch?*)searcher?result:(BMKPoiResult?*)poiResulterrorCode:(BMKSearchErrorCode)errorCode{
NSMutableArray?*poiAnnotations?=?[NSMutableArrayarrayWithCapacity:poiResult.poiInfoList.count];
//移除地圖的標(biāo)注和覆蓋物
NSArray?*array?=?[NSArrayarrayWithArray:self.mapView.annotations];
[self.mapViewremoveAnnotations:array];
if(errorCode?==?BMK_SEARCH_NO_ERROR)?{
NSLog(@"找到結(jié)果");
for(inti?=?0;?i
BMKPoiInfo?*info?=?[poiResult.poiInfoListobjectAtIndex:i];
BMKPointAnnotation?*pointAnnotation?=?[BMKPointAnnotationnew];
pointAnnotation.coordinate?=?info.pt;
pointAnnotation.title?=?info.name;
pointAnnotation.subtitle?=?[NSStringstringWithFormat:@"%@%@",info.city,info.address];
[poiAnnotationsaddObject:pointAnnotation];
if(i==0)?{
self.mapView.centerCoordinate?=?info.pt;
geoName?=?info.name;
addr?=?info.address;
pt?=?info.pt;
BMKPoiDetailShareURLOption?*option?=?[BMKPoiDetailShareURLOptionnew];
option.uid?=?info.uid;
BOOLflag?=?[self.shareSearchrequestPoiDetailShareURL:option];
if(!flag)?{
NSLog(@"詳情url檢索發(fā)送失敗");
}
}
}
[self.mapViewaddAnnotations:poiAnnotations];
[self.mapViewselectAnnotation:[poiAnnotationsobjectAtIndex:0]?animated:YES];
}elseif?(errorCode?==?BMK_SEARCH_AMBIGUOUS_KEYWORD){
NSLog(@"起始點(diǎn)有歧義,有相同名字的別的城市:%@",poiResult.cityList);
}else{
NSLog(@"未找到結(jié)果");
}
}
-?(void)onGetPoiDetailShareURLResult:(BMKShareURLSearch?*)searcher?result:(BMKShareURLResult?*)result?errorCode:(BMKSearchErrorCode)error
{
shortUrl?=?result.url;
if(error?==?BMK_SEARCH_NO_ERROR)
{
showmeg?=?[NSStringstringWithFormat:@"這里是:%@\r\n%@\r\n%@",geoName,addr,shortUrl];
UIAlertView?*myAlertView?=?[[UIAlertViewalloc]?initWithTitle:@"短串分享"message:showmegdelegate:selfcancelButtonTitle:nilotherButtonTitles:@"分享",@"取消",nil];
myAlertView.tag?=?1000;
[myAlertViewshow];
}
}
-?(void)alertView:(UIAlertView?*)alertViewclickedButtonAtIndex:(NSInteger)buttonIndex
{
if(alertView.tag?==1000?)
{
if(buttonIndex?==?0)
{
Class?messageClass?=?(NSClassFromString(@"MFMessageComposeViewController"));
if(messageClass?!=?nil)?{
if([messageClasscanSendText])?{
MFMessageComposeViewController?*picker?=?[[MFMessageComposeViewControlleralloc]?init];
picker.messageComposeDelegate?=?self;
picker.body?=?[NSStringstringWithFormat:@"%@",showmeg];
[selfpresentModalViewController:pickeranimated:YES];
}else{
UIAlertView?*myAlertView?=?[[UIAlertViewalloc]?initWithTitle:@"當(dāng)前設(shè)備無法發(fā)送短信"message:nildelegate:selfcancelButtonTitle:nilotherButtonTitles:@"確定",nil];
[myAlertViewshow];
}}}}}
-?(void)messageComposeViewController:(MFMessageComposeViewController?*)controller
didFinishWithResult:(MessageComposeResult)result
{
switch(result)?{
caseMessageComposeResultCancelled://用戶自己取消瞻离,不用提醒
break;
caseMessageComposeResultSent://后續(xù)可能不能夠成功發(fā)送腾仅,所以暫時(shí)不提醒
break;
caseMessageComposeResultFailed:?NSLog(@"短信發(fā)送失敗");
break;
default:??NSLog(@"短信沒有發(fā)送");
break;
}
[selfdismissModalViewControllerAnimated:YES];
}
-(void)viewWillDisappear:(BOOL)animated?{
[superviewWillDisappear:animated];
NSArray?*array?=?[NSArrayarrayWithArray:self.mapView.annotations];
[self.mapViewremoveAnnotations:array];
self.poiSearch.delegate?=?nil;
self.shareSearch.delegate?=?nil;
}
測試日志
周邊興趣點(diǎn)搜索:
遇到問題
1.剛開始開啟百度服務(wù)的時(shí)候,一直無法顯示百度地圖圖層套利,筆者確定了APPKEY正確推励,keyStatus也返回的是0,但就是無法顯示肉迫。
最后確定出錯原因在ARC验辞,在開啟ARC的項(xiàng)目中,BMKMapManager一定要在頭文件里面聲明屬性喊衫。
2.在使用調(diào)起百度導(dǎo)航的時(shí)候需要配置URL
scheme并使用跌造,在代碼中需要設(shè)置appScheme,筆者按照URL
Schemes+”://”+Identifier的方式拼接字符串族购,發(fā)現(xiàn)不能調(diào)啟壳贪。原因是Identifier拼接的時(shí)候要反向?qū)懀?/p>
如”com.baidu.mapsdk”要改寫成”mapsdk.baidu.com”寝杖。
上手難易
百度地圖上手難度一般违施,需要掌握面向?qū)ο蟮拈_發(fā)模式,按照百度SDK提供的相關(guān)接口調(diào)用方法瑟幕。代理實(shí)現(xiàn)返回的功能則需要開發(fā)者自己去定義磕蒲。
開發(fā)文檔
關(guān)于百度地圖iOS SDK的開發(fā)文檔,請參考鏈接:
http://developer.baidu.com/map/sdk-ios.htm
對于想使用API開發(fā)更豐富功能的開發(fā)者話收苏,請參考SDK的類文檔:
http://developer.baidu.com/map/ios_refer/html/annotated.html
此服務(wù)評測版權(quán)歸DevStore所有亿卤,禁止轉(zhuǎn)載愤兵,申請升級為特約評測員才可進(jìn)行測評立即申請
聲明:DevStore評測內(nèi)容都是基于專業(yè)評測人員/開發(fā)者通過真實(shí)的測試之后得出的數(shù)據(jù)鹿霸,服務(wù)版本實(shí)時(shí)都在更新,所以評測并不一定
是此服務(wù)的最新版本秆乳,但我們會秉承公正專業(yè)精準(zhǔn)的態(tài)度懦鼠,對開發(fā)者負(fù)責(zé),同時(shí)歡迎大家監(jiān)督和建議屹堰,如對評測內(nèi)容有異議肛冶,請?zhí)峤患m錯,由專業(yè)的評測團(tuán)隊(duì)再次評
測扯键,我們會盡最大努力為大家提供更貼心的服務(wù)睦袖。
DevStore_全球首家第三方開發(fā)者服務(wù)商店,最精準(zhǔn)的服務(wù)對比荣刑、最專業(yè)的服務(wù)評測馅笙、最及時(shí)的行業(yè)動態(tài)伦乔,為開發(fā)者挑選服務(wù)提供最全面的參考和專業(yè)分析,加入DevStore董习,從此告別熬夜加班烈和,你也可以這么帥!搜索微信號:DevStore