关于导入百度地图SDK出现的问题(二)
1.百度地图开发中添加标注[_mapView addAnnotations:annotations]与[_mapView addAnnotation: annotation] 的不同
/**
*向地图窗口添加标注,需要实现BMKMapViewDelegate的-mapView:viewForAnnotation:函数来生成标注对应的View
*@param annotation 要添加的标注
*/
- (void)addAnnotation:(id <BMKAnnotation>)annotation;
/**
*向地图窗口添加一组标注,需要实现BMKMapViewDelegate的-mapView:viewForAnnotation:函数来生成标注对应的View *@param annotations 要添加的标注数组
*/
- (void)addAnnotations:(NSArray *)annotations;addAnnotation是每次添加一个标注,之后在- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation;
中paopaoView的显示内容是不同的,addAnnotation是添加一个标注数组,之后(BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation;
paopaoview显示的内容是数组最后一个元素的内容。
2.百度地图api自定义paopaoView,push到一个新的界面,返回之后再点击paopaoView不在有反应,解决办法:
下面这两个方法(void)mapView:(BMKMapView *)mapView didAddAnnotationViews:(NSArray *)views;
和
- (void)mapView:(BMKMapView*)mapView annotationViewForBubble:(BMKAnnotationView *)view;
不要使用, 在自定义的泡泡view里最上面覆盖一个透明的按钮,之后在- (BMKAnnotationView )mapView:(BMKMapView)mapView viewForAnnotation:(id )annotation这个方法里初始化自定义的View,之后为view里的按钮添加一个监听事件,为button设置tag值,之后在点击方法里
//pragma mark paopao按钮点击
-(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; //计算所选坐标和当前位置之间的距离 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];
}
}
}
就可以跳转到对应的界面了。
3.设置状态栏为白色的方法
//pragma mark 设置状态栏的为白色
-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
//pragma mark 设置状态栏的为白色
-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
4.自定义导航栏侧滑返回失效
-(void)viewDidLoad {
[super viewDidLoad];
__weak typeof (self) weakSelf = self;
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.interactivePopGestureRecognizer.delegate = weakSelf;
}
}
iOS7之后可以添加一个手势,要设置代理UIGestureRecognizerDelegate
//支持右滑手势
if ([[[UIDevice currentDevice] systemVersion] floatValue]>=7) {
self.navigationController.interactivePopGestureRecognizer.delegate=self;
}
5.BMKMapPoint * temppoints = new BMKMapPoint[planPointCounts]; ‘delete []temppoints;’报错
解决办法:new和delete是c++里的语法。要么把源文件后缀名改成.mm要么用c的malloc。这其实是objc开发的问题了,不算百度SDK的问题。
网友评论