业界动态
苹果自带地图定位 经纬度苹果手机怎么看经纬度「苹果自带地图定位 经纬度」
2025-04-08 08:00

1.创建导航 在导航上创建定位按钮

2.引入两个依赖库 一个是地图的 一个是定位的
在这里插入图片描述在VC.m里面
引入两个框架 地图和定位的框架

#import “ViewController.h”
//引入头文件 ‘地图框架’
#import <MapKit/MapKit.h>
//引入头文件 ‘定位框架’
#import <CoreLocation/CoreLocation.h>
@interface ViewController ()<MKMapViewDelegate , CLLocationManagerDelegate>
//定义属性 ‘地图视图’
@property(nonatomic,strong)MKMapView *MapView;
//定义属性 ‘地理位置管理者’
@property(nonatomic,strong)CLLocationManager *locManager;
@end

@implementation ViewController

  • (void)viewDidLoad {
    [super viewDidLoad];

    self.title = @“地图”;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@“附近违章高发地” style:UIBarButtonItemStyleDone target:self action:@selector(click)];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@“定位” style:UIBarButtonItemStyleDone target:self action:@selector(currentBtnDidPress:)];

    //初始化MKMapView ‘地图视图’
    self.MapView = [[MKMapView alloc]initWithframe:self.view.frame];
    //设置地图的样式 ‘MKMapTypeSatellite卫星地图’ ‘MKMapTypeStandard平面地图’
    self.MapView.mapType = MKMapTypeStandard;
    //签订协议
    self.MapView.delegate = self;
    //添加到视图
    [self.view addSubview:self.MapView];

    //实例化位置管理者对象
    self.locManager = [[CLLocationManager alloc]init];
    //签订协议
    self.locManager.delegate = self;
    //申请用户授权
    [self.locManager requestWhenInUseAuthorization];

}
-(void)click{

// NextViewController *next = [[NextViewController alloc]init];
// [self.navigationController pushViewController:next animated:YES];

}
//获取当前按钮触发
-(void)currentBtnDidPress:(id)sender{

 

}

//获取当前位置信息后触发的回调方法
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{

 

}
//设置锚点视图的回调方法,当地图调用addAnnotation:方法时会触发 点击大头针是触发的方法
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation{
//静态字符串标识
static NSString *iden = @“pin”;
//初始化描点视图
MKPinAnnotationView *pin = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:iden];

 

}

    以上就是本篇文章【苹果自带地图定位 经纬度苹果手机怎么看经纬度「苹果自带地图定位 经纬度」】的全部内容了,欢迎阅览 ! 文章地址:http://www.uqian.cn/news/6619.html 
     资讯      企业新闻      行情      企业黄页      同类资讯      首页      网站地图      返回首页 极顶速云移动站 http://m.uqian.cn/ , 查看更多   

点击拨打: