系统自带地图 框架: 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:跟随用户的位置和角度移动
原文:http://www.cnblogs.com/Ager/p/4986343.html