在iOS中 简单使用MKMapView显示地图

本文介绍如何在iOS应用中使用MKMapView显示地图,并设置了混合地图类型及显示用户位置等功能。

        在应用开发中,经常会使用到显示地图的功能,地位功能,在ios中 使用MKMapVIew类显示地图, 使用MKMapView 前必须先导入MapKit.framework.

        点击项目target->summary 添加 Mapkit.framework.

       在ViewController.h头文件中导入 #import <MapKit/MapKit.h> 

    

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
@interface ViewController : UIViewController
@property (nonatomic,strong) MKMapView * myMapView;
@end
    

       在ViewController.m 文件的viewDidLoad 方法中添加如下代码   


#import "ViewController.h"
#import "MyAnnotation.h"

@interface ViewController () <MKMapViewDelegate>

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    self.view.backgroundColor = [UIColor whiteColor];
    self.myMapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
    self.myMapView.mapType = MKMapTypeHybrid;
    self.myMapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    self.myMapView.delegate = self;
   //显示当前位置
    self.myMapView.showsUserLocation = YES;

    [self.view addSubview:self.myMapView];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return YES;
}




@end

MKMapView 地图类型mapType 属性 有三种类型:

enum {

    MKMapTypeStandard = 0,

    MKMapTypeSatellite,

    MKMapTypeHybrid

};

typedef NSUInteger MKMapType;



转载于:https://my.oschina.net/CarlHuang/blog/135589

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值