使用苹果地图 不需要使用第三方 不需要导入依赖库
直接在VC.m中
导入头文件
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
给地图的代理方法
<MKMapViewDelegate,CLLocationManagerDelegate>
定义属性
@property(nonatomic,strong)MKMapView *mapview;
下面就是代码了
-
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.//初始化
self.mapview = [[MKMapView alloc] initWithFrame:self.view.frame];
//设置地图的显示类型
[self.mapview setMapType:MKMapTypeMutedStandard];
//设置缩放
[self.mapview setZoomEnabled:YES];
//设置滑动
[self.mapview setScrollEnabled:YES];
//设置旋转
[self.mapview setRotateEnabled:YES];
//显示当前的位置
[self.mapview setShowsUserLocation:YES];
//代理方法
self.mapview.delegate = self;
//当前八维的位置
[self locateToLatitude:40.045612 longtitude:116.30612];[self.view addSubview:self.mapview];
}
-(void)locateToLatitude:(CLLocationDegrees)latitude longtitude:(CLLocationDegrees)longtitude{
//设置地图中心的经纬度
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(latitude, longtitude);
//设置地图显示范围
MKCoordinateSpan span = MKCoordinateSpanMake(0.1, 0.1);
MKCoordinateRegion region = MKCoordinateRegionMake(center, span);
//显示
[self.mapview setRegion:region animated:YES];
}
显示的地图