iOS百度地圖問(wèn)題總結(jié)(四)

關(guān)于導(dǎo)入百度地圖SDK出現(xiàn)的問(wèn)題(二)


原帖地址


1.百度地圖開發(fā)中添加標(biāo)注[_mapView addAnnotations:annotations]與[_mapView addAnnotation: annotation] 的不同

/** 
*向地圖窗口添加標(biāo)注,需要實(shí)現(xiàn)BMKMapViewDelegate的-mapView:viewForAnnotation:函數(shù)來(lái)生成標(biāo)注對(duì)應(yīng)的View 
*@param annotation 要添加的標(biāo)注
 */
- (void)addAnnotation:(id <BMKAnnotation>)annotation;
/** 
*向地圖窗口添加一組標(biāo)注,需要實(shí)現(xiàn)BMKMapViewDelegate的-mapView:viewForAnnotation:函數(shù)來(lái)生成標(biāo)注對(duì)應(yīng)的View *@param annotations 要添加的標(biāo)注數(shù)組 
*/
- (void)addAnnotations:(NSArray *)annotations;addAnnotation是每次添加一個(gè)標(biāo)注,之后在- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation;
中paopaoView的顯示內(nèi)容是不同的,addAnnotation是添加一個(gè)標(biāo)注數(shù)組,之后(BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation;

paopaoview顯示的內(nèi)容是數(shù)組最后一個(gè)元素的內(nèi)容。


2.百度地圖api自定義paopaoView,push到一個(gè)新的界面,返回之后再點(diǎn)擊paopaoView不在有反應(yīng),解決辦法:

下面這兩個(gè)方法(void)mapView:(BMKMapView *)mapView didAddAnnotationViews:(NSArray *)views;

  • (void)mapView:(BMKMapView*)mapView annotationViewForBubble:(BMKAnnotationView *)view;
    不要使用, 在自定義的泡泡view里最上面覆蓋一個(gè)透明的按鈕,之后在- (BMKAnnotationView )mapView:(BMKMapView)mapView viewForAnnotation:(id )annotation這個(gè)方法里初始化自定義的View,之后為view里的按鈕添加一個(gè)監(jiān)聽事件,為button設(shè)置tag值,之后在點(diǎn)擊方法里
//pragma mark paopao按鈕點(diǎn)擊
-(void)btnClick:(UIButton *)button{ 
for (int i = 0; i < self.annotations.count; i++) { 
HXMenDList *menDList = self.annotations[i]; 
if (button.tag == [menDList.ID integerValue]) { 
HXDetailsController *detailsV = [[HXDetailsController alloc] init]; 
detailsV.menDList = menDList; //計(jì)算所選坐標(biāo)和當(dāng)前位置之間的距離 CLLocationCoordinate2D 
currentAnno = CLLocationCoordinate2DMake([menDList.weid doubleValue], [menDList.jind doubleValue]); BMKMapPoint mp1 = 
BMKMapPointForCoordinate(currentAnno); 
BMKMapPoint mp2 = BMKMapPointForCoordinate(self.userLocation.location.coordinate);
 CLLocationDistance distance = BMKMetersBetweenMapPoints(mp1, mp2); 
distance = [Tools formatDistance:distance]; 
menDList.distance = distance; 
NSLog(@"detailsV.menDList.dianm==%@",detailsV.menDList.dianm);
[self.navigationController pushViewController:detailsV animated:YES]; 
} 
}
}

就可以跳轉(zhuǎn)到對(duì)應(yīng)的界面了。

3.設(shè)置狀態(tài)欄為白色的方法

//pragma mark 設(shè)置狀態(tài)欄的為白色
-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
 [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
//pragma mark 設(shè)置狀態(tài)欄的為白色
-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
 [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}

4.自定義導(dǎo)航欄側(cè)滑返回失效

-(void)viewDidLoad { 
[super viewDidLoad];
__weak typeof (self) weakSelf = self; 
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) { 
self.interactivePopGestureRecognizer.delegate = weakSelf; 
}
}

iOS7之后可以添加一個(gè)手勢(shì),要設(shè)置代理UIGestureRecognizerDelegate

//支持右滑手勢(shì) 
if ([[[UIDevice currentDevice] systemVersion] floatValue]>=7) { 
self.navigationController.interactivePopGestureRecognizer.delegate=self;
 }

5.BMKMapPoint * temppoints = new BMKMapPoint[planPointCounts]; ‘delete []temppoints;’報(bào)錯(cuò)

解決辦法:new和delete是c++里的語(yǔ)法。要么把源文件后綴名改成.mm要么用c的malloc。這其實(shí)是objc開發(fā)的問(wèn)題了,不算百度SDK的問(wèn)題。

下面是 demo 下載地址:

github 下載地址

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容