Creating a Map View

 

Problem

You want to instantiate and display a map on a view

Solution

Create an instance of the MKMapView class and add it to a view or assign it as a subview of your view controller that creates an instance

Of MKMapView and displays it full-screen on its view

 

#import "WSYViewController.h"

#import <MapKit/MapKit.h>

@interface WSYViewController ()

@property (nonatomic,strong)MKMapView * myMapView;

@end

 

@implementation WSYViewController

 

- (void)viewDidLoad

{

    [super viewDidLoad];

   

    self.view.backgroundColor = [UIColor whiteColor];

   

    self.myMapView = [[MKMapView alloc] initWithFrame:self.view.frame];

   

    //set the map type to satellite

   

    self.myMapView.mapType = MKMapTypeSatellite;

   

    self.myMapView.autoresizingMask =

    UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;

   

    //add it to our view

    [self.view addSubview:self.myMapView];

}

 

//this is a simple root view controller with a variable of type MKMapView.Later

// in the implementation of this view controller we will initalize the map and set its type to satellite like so

 

@end

 

posted @ 2014-05-29 19:28  秋怀瑾  阅读(154)  评论(0编辑  收藏  举报