(app.m)
#import "GDViewController.h"//高德视图
#import //高德地图
//高德地图添加开启 HTTPS 功能的代码
[[AMapServices sharedServices] setEnableHTTPS:YES];
//注册高德地图
[AMapServices sharedServices].apiKey= @"186aef70770a871729391226cb0b838a";
(GD.m)
#import
#import
@interface GDViewController ()
@property(nonatomic,strong)MAMapView * mapView;
@property(nonatomic,strong)CLLocationManager * manager;(协议和创建对象)
//实现地图的视图
-(MAMapView * )mapView
{
if(!_mapView)
{
_mapView=[[MAMapView alloc]initWithFrame:self.view.frame];
//设置为普通地图
_mapView.mapType=MAMapTypeStandard;
//设置地图的语言为中文
_mapView.language=MAMapLanguageZhCN;
//显示当前用户的位置,小蓝光标
_mapView.showsUserLocation=YES;
//显示路径的模型
_mapView.userTrackingMode=MAUserTrackingModeFollow;
//设置地图的代理
_mapView.delegate=self;
}
return _mapView;
}
//实现更新位置的管理对象manager;
-(CLLocationManager * )manager
{
if(!_manager)
{
_manager=[CLLocationManager new];
//设置代理
_manager.delegate=self;
}
return _manager;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.navigationBar.translucent=NO;
//设置导航条的标题
self.navigationItem.title=@"高德地图";
//添加高德地图
[self.view addSubview:self.mapView];
//设置导航定位按钮
self.navigationItem.rightBarButtonItem=[[UIBarButtonItemalloc]initWithTitle:@"定位" style:UIBarButtonItemStyleDone target:selfaction:@selector(dingwei)];
//设置分享按钮
self.navigationItem.leftBarButtonItem=[[UIBarButtonItemalloc]initWithTitle:@"分享" style:UIBarButtonItemStyleDone target:selfaction:@selector(fenxiang)];
}
//实现定位按钮
-(void)dingwei
{
//开始跟新地理位置的信息
[self.manager startUpdatingLocation];
}
//实现manager的协议方法
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
//获取当前的位置
CLLocation * curlocation=[locations lastObject];
//获取当前位置的经纬度
CLLocationCoordinate2D curjingwei=curlocation.coordinate;
dispatch_async(dispatch_get_main_queue(), ^{
//设置地图显示的区域
MACoordinateRegionshowRegion=MACoordinateRegionMakeWithDistance(curjingwei, 1000, 1000);
[self.mapView setRegion:showRegion animated:YES];
//实例化一个大头针
MAPointAnnotation * point=[MAPointAnnotation new];
//设置大头针的坐标
point.coordinate=curjingwei;
//显示大头针的标题信息
point.title=@"您当前所在的位置";
//地理位置反向解析
CLGeocoder * geocoder=[CLGeocoder new];
[geocoder reverseGeocodeLocation:curlocation completionHandler:^(NSArray * _Nullable placemarks, NSError * _Nullable error) {
CLPlacemark * place=[placemarks lastObject];
point.subtitle=place.name;
//回到UI主线程,给地图添加主视图
dispatch_async(dispatch_get_main_queue(), ^{
[self.mapView addAnnotation:point];
self.manager=nil;
});
}];
});
}
//实现分享按钮
-(void)fenxiang
{
}
-------------------------------------------------------
(第三方)
MAMapKit.framework
AMapFoundationKit.framework
AMap.bundle
(依赖库)
libc++.tbd
libz.tbd
MAMapKit.framework
SystemConfiguration.framework
CoreTelephony.framework
AMapFoundationkit.framework
(info.plist)
+NSLocationAlwaysAndWhenInUseUsageDescription
+
Application Category
+
Privacy - Location When In Use Usage Description
网友评论