iOS地图展示mapkit框架-基本使用

来源:互联网 发布:win10查看电脑mac地址 编辑:程序博客网 时间:2024/05/19 16:38

1.地图的类型


普通地图   

 卫星云图  

混合模式  

1.1在这里设置地图的模式


代码设置地图模式

  self.mapView.mapType = MKMapTypeSatelliteFlyover;

 /**     MKMapTypeStandard = 0,     MKMapTypeSatellite,     MKMapTypeHybrid,     MKMapTypeSatelliteFlyover NS_ENUM_AVAILABLE(10_11, 9_0), //3d     MKMapTypeHybridFlyover NS_ENUM_AVAILABLE(10_11, 9_0),    //3d混合模式     */

#import "ViewController.h"#import <MapKit/MapKit.h>#import <CoreLocation/CoreLocation.h>@interface ViewController ()<MKMapViewDelegate>@property (weak, nonatomic) IBOutlet MKMapView *mapView;/**   */@property (nonatomic, strong) CLLocationManager *lM;@end@implementation ViewController- (CLLocationManager *)lM{    if (!_lM) {        _lM = [[CLLocationManager alloc] init];        if ([_lM respondsToSelector:@selector(requestAlwaysAuthorization)])        {            [_lM requestAlwaysAuthorization];        }    }    return _lM;}- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view, typically from a nib.}- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{    /**     MKMapTypeStandard = 0,     MKMapTypeSatellite,     MKMapTypeHybrid,     MKMapTypeSatelliteFlyover NS_ENUM_AVAILABLE(10_11, 9_0),     MKMapTypeHybridFlyover NS_ENUM_AVAILABLE(10_11, 9_0),     *///    self.mapView.mapType = MKMapTypeSatelliteFlyover;        //    self.mapView.zoomEnabled = NO;//    ////    self.mapView.showsCompass = NO;//    self.mapView.showsScale = YES;        [self lM];    self.mapView.showsUserLocation = YES;    //    self.mapView.userTrackingMode = MKUserTrackingModeFollowWithHeading;    }#pragma mark - MKMapViewDelegate/** *  更新到位置 * *  @param mapView      地图 *  @param userLocation 位置对象 */-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{    /**     *  MKUserLocation (大头针模型)     *     *     */    userLocation.title = @"重庆";    userLocation.subtitle = @"西永软件园";    // 设置地图显示中心//    [self.mapView setCenterCoordinate:userLocation.location.coordinate animated:YES];    // 设置地图显示区域    MKCoordinateSpan span = MKCoordinateSpanMake(0.051109, 0.034153);    MKCoordinateRegion region = MKCoordinateRegionMake(userLocation.location.coordinate, span);    [self.mapView setRegion:region animated:YES];}//-(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated//{//    NSLog(@"%f----%f", mapView.region.span.latitudeDelta, mapView.region.span.longitudeDelta);//}


0 0