美文网首页iOS-VendorIosios常用技巧
iOS百度地图问题总结(四)

iOS百度地图问题总结(四)

作者: hrscy | 来源:发表于2015-11-10 23:06 被阅读2013次

    关于导入百度地图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的问题。

    下面是 demo 下载地址:

    github 下载地址

    相关文章

      网友评论

      • iOS_小胜:大神,问下你new和delect怎么翻成malloc和free,我怎么写得老是报错
        hrscy:那是 C++的写法,这里没用到吧
      • 0271fb6f797c:牛牛牛,太厉害了

      本文标题: iOS百度地图问题总结(四)

      本文链接:https://www.haomeiwen.com/subject/xlshhttx.html