设为首页 加入收藏

TOP

CoreLocation MKMapView 地图
2017-10-11 17:46:48 】 浏览:5121
Tags:CoreLocation MKMapView 地图

系统自带地图  框架: CoreLocation MapKit

CLLocationManager --> 定位管理者  CLGeocoder --> 地理编码器 MKMapView --> 地图view

允许用户定位
    [_locationManager requestAlwaysAuthorization];//总是允许
    [_locationManager requestWhenInUseAuthorization];//用户用时允许

用户移动100米的时候才会再次调用位置代理方法
    _locationManager.distanceFilter = 100.0;

开始定位

  [_locationManager startUpdatingLocation];

CLLocationManager 代理方法:(获取到信息室处理)

  - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{
  }

创建比例系数  显示在哪个点上
   MKCoordinateRegion region = MKCoordinateRegionMake(userLocation.coordinate, MKCoordinateSpanMake(0.1, 0.1));
   比例系数赋值
   _mapView.region = region;


CLGeocoder:

编码:提供某个字符串 来定位位置:- (void)geocodeAddressString:(NSString *)addressString completionHandler:(CLGeocodeCompletionHandler)completionHandler;

反编码:根据位置显示该地方的名字等等[_geocoder reverseGeocodeLocation:placemark.location  completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {}];

添加大头针:

  AGAnnotion *agAnnotion = [[AGAnnotion alloc]init];
    agAnnotion.coordinate = CLLocationCoordinate2DMake(36.0, 120.0);
    agAnnotion.title = @"coco";
    [_mapView addAnnotation:agAnnotion];
自定义气泡

  继承 NSObject , 遵守 MKAnnotation 协议

  创建三个属性

  @property (nonatomic, assign) CLLocationCoordinate2D coordinate;
  @property (nonatomic, copy) NSString *title;
  @property (nonatomic, copy) NSString *subtitle;

 高德:

 1. 验证key
    [MAMapServices sharedServices].apiKey = @“申请的key”;
 2. 初始化
    mapView = [[MAMapView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.bounds))];
    mapView.delegate = self;
    mapView.language = MAMapLanguageEn; // 设置地图显示语言
    mapView.mapType = MAMapTypeStandard; // 地图类型
    /*
     MAMapTypeSatellite:卫星地图
     MAMapTypeStandard:标准地图
     */

    mapView.showTraffic = YES; // 显示实时交通路况
    [self.view addSubview:mapView];
    mapView.showsUserLocation = YES;

mapView的定位模式: userTrackingMode

  MAUserTrackingModeNone:不跟随用户位置,仅在地图上显示。

  MAUserTrackingModeFollow:跟随用户位置移动,并将定位点设置成地图中心点

  MAUserTrackingModeFollowWithHeading:跟随用户的位置和角度移动

系统的地图和 高德地图 的区别

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇简易音乐播放器制作 下一篇Objective-C学习篇05—Foundation..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目