zoukankan      html  css  js  c++  java
  • iOS_SN_地图的使用(3)

    地图的定位,记得不用定位的时候要关掉定位不然会一直定位,使电量使用过快。

    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
        
        self.mapView = [[BMKMapView alloc] initWithFrame:CGRectMake(0, 0, kwidth, kheigth)];
        //    [self.mapView setZoomLevel:14];
        [self.view addSubview:self.mapView];
        
        //初始化BMKLocationService
        _locService = [[BMKLocationService alloc]init];
        _locService.delegate = self;
        //启动LocationService
        [_locService startUserLocationService];
    
    }
    
    
    //实现相关delegate 处理位置信息更新
    //处理方向变更信息
    - (void)didUpdateUserHeading:(BMKUserLocation *)userLocation
    {
        //NSLog(@"heading is %@",userLocation.heading);
        
        NSLog(@"%@--%@--%f--%f",userLocation.title,userLocation.subtitle,userLocation.location.altitude,userLocation.location.altitude);
        
    }
    //处理位置坐标更新
    - (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
    {
        
        _mapView.showsUserLocation = YES;//显示定位图层
        [_mapView updateLocationData:userLocation];
    
        
        NSLog(@"didUpdateUserLocation lat %f,long %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);
    }
    

      自定义大头针,要先自定义大头针模型,其核心代码如下:

    - (BMKAnnotationView *)mapView:(BMKMapView *)view viewForAnnotation:(id <BMKAnnotation>)annotation
    {
        static NSString *AnnotationViewID = @"annotationViewID";
        MyPointAnnotation *myAnnotation = (MyPointAnnotation *)annotation;
        MyAnnotationView *annotationView = (MyAnnotationView *)[view dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
        if (annotationView == nil)
        {
            annotationView = [[MyAnnotationView alloc] initWithFrame:CGRectMake(0, 0, 27, 30) viewForAnnotation:myAnnotation reuseIdentifier:AnnotationViewID];
            annotationView.image = [UIImage imageNamed:@"定位.png"];
        }
        else
        {
            annotationView.myAnnotation = myAnnotation;
            [annotationView setNeedsLayout];
        }
        annotationView.annotation = myAnnotation;
        annotationView.canShowCallout = true;
        return annotationView;
    }
    

      下面有一个整体的demo会贴出来。

    本文GitHub地址https://github.com/zhangkiwi/iOS_SN_BDMap-Test

  • 相关阅读:
    【GO】文件二进制读取
    【JAVA】IO FileInputStream 读取二进制文件
    【JAVA】Maven 常用命令
    【JAVA】java8 function apply() compose() andThen()
    【Java】Maven resoucese 目录文件获取
    【数据结构】线索二叉树
    【Java】Java中的null作为方法参数是被当做值传递
    【Python】《Effective Python》 读书笔记 (一)
    【Python】一个try/except/else/finally 组合使用的例子
    【数据结构】二叉树的创建与遍历
  • 原文地址:https://www.cnblogs.com/zhang-kiwi/p/5263581.html
Copyright © 2011-2022 走看看