MapKit的学习一

来源:互联网 发布:电商平台数据 编辑:程序博客网 时间:2024/05/22 10:50

MapKit的简单使用
注意
1.使用控件mapkitview出现下面的错误需要手动导入框架MapKit

'Could not instantiate class named MKMapView'

这里写图片描述

2.中国区默认的地图是高德地图(苹果在中国的地图代理商)

3.iOS9下依然需要先设置CLLocationManager,否则开启不了定位服务

////  ViewController.m//  MapKitTest////  Created by LoveQiuYi on 16/2/23.//  Copyright © 2016年 LoveQiuYi. All rights reserved.//#import "ViewController.h"#import <MapKit/MapKit.h>#import <CoreLocation/CoreLocation.h>@interface ViewController ()<CLLocationManagerDelegate,MKMapViewDelegate>@property (weak, nonatomic) IBOutlet MKMapView *mapView;@property (nonatomic ,strong) CLLocationManager * locMgr;@end@implementation ViewController-(CLLocationManager *)locMgr{    if (!_locMgr) {        self.locMgr = [[CLLocationManager alloc]init];    }    return _locMgr;}- (void)viewDidLoad {    [super viewDidLoad];    self.locMgr.delegate = self;    //地图代理->监控地图的相关行为    self.mapView.delegate = self;    [self.locMgr requestAlwaysAuthorization];    [self.locMgr requestWhenInUseAuthorization];    [self.locMgr startUpdatingLocation];    //设置地图的类型    self.mapView.mapType = MKMapTypeStandard ;    /**     *  MKMapTypeStandard普通地图        MKMapTypeSatellite卫星云图        MKMapTypeHybrid普通地图覆盖到卫星地图上面     */    //设置跟踪模式->高德地图会自动跟踪到这个位置    self.mapView.userTrackingMode = MKUserTrackingModeFollow;}#pragma mark - mapViewDelegate/** *  更新到用户位置的时候调用 *  @param userLocation 模型数据,对大头针位置的封装 */-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{    userLocation.title = @"SKT-T1-Keyoubi";    userLocation.subtitle = @"zhangxin";}/** *  地图显示的区域已经改变了调用->拖拽地图后结束拖拽 */-(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{    NSLog(@"地图已经改变了");    CLLocationCoordinate2D center = mapView.region.center;    MKCoordinateSpan span = mapView.region.span;    NSLog(@"中心点为 = (%f,%f),跨度区域为 = (%f,%f)",center.longitude,center.latitude,span.longitudeDelta,span.latitudeDelta);}/** *  地图显示的区域将要改变的时候调用->拖拽地图不放开鼠标 */-(void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated{    NSLog(@"地图将要改变");}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}@end
0 0
原创粉丝点击