2014-05-16 45 views
0

我有我的iPhone应用程序加载地图视图,我的问题是它将地图视图加载到一个单一的地图引脚上,我希望它加载一个更全面的视图,显示整个地图美国的权利,当应用程序启动。有没有办法执行这个?这里是我的代码:地图视图查看问题

ViewController.h

#import <UIKit/UIKit.h> 
#import <MapKit/MapKit.h> 

@interface ViewController : UIViewController 
{ 
MKMapView *mapView; 
} 

@property (nonatomic, retain) IBOutlet MKMapView *mapView; 

-(IBAction)SetMap:(id)sender; 

-(IBAction)GetLocation:(id)sender; 

-(IBAction)Directions:(id)sender; 

@end 

ViewController.m

#import "ViewController.h" 
#import "MapPin.h" 

@interface ViewController() 

@end 

@implementation ViewController 

@synthesize mapView; 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 

//Moss Preserve coordinates 
MKCoordinateRegion MossPreserveRegion = { {0.0, 0.0}, {0.0, 0.0}}; 
MossPreserveRegion.center.latitude = 33.3816566; 
MossPreserveRegion.center.longitude = -86.8415451; 
MossPreserveRegion.span.longitudeDelta = 0.01f; 
MossPreserveRegion.span.latitudeDelta = 0.01f; 
[mapView setRegion:MossPreserveRegion animated:YES]; 

//Moss Preserve annotation and map pin 
MapPin *MossPreserveAnnotation = [[MapPin alloc] init]; 
MossPreserveAnnotation.title = @"Moss Rock Preserve Boulder Fields"; 
MossPreserveAnnotation.subtitle = @"Preserve Pkwy, Hoover, AL"; 
MossPreserveAnnotation.coordinate = MossPreserveRegion.center; 
[mapView addAnnotation:MossPreserveAnnotation]; 

//Horse Pens 40 coordinates 
MKCoordinateRegion HorsePenRegion = { {0.0, 0.0}, {0.0, 0.0}}; 
HorsePenRegion.center.latitude = 33.9207535; 
HorsePenRegion.center.longitude = -86.3089447; 
HorsePenRegion.span.longitudeDelta = 0.01f; 
HorsePenRegion.span.latitudeDelta = 0.01f; 
[mapView setRegion:HorsePenRegion animated:YES]; 

//Horse Pens 40 annotation and map pin 
MapPin *HorsePenAnnotation = [[MapPin alloc] init]; 
HorsePenAnnotation.title = @"Horse Pens 40"; 
HorsePenAnnotation.subtitle = @"Steele, AL "; 
HorsePenAnnotation.coordinate = HorsePenRegion.center; 
[mapView addAnnotation:HorsePenAnnotation]; 
} 

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

-(IBAction)SetMap:(id)sender; 
{ 
switch (((UISegmentedControl *) sender).selectedSegmentIndex) 
{ 
    case 0: 
     mapView.mapType = MKMapTypeStandard; 
     break; 
    case 1: 
     mapView.mapType = MKMapTypeSatellite; 
     break; 
    case 2: 
     mapView.mapType = MKMapTypeHybrid; 
     break; 

    default: 
     break; 
} 
} 

-(IBAction)GetLocation:(id)sender; 
{ 
mapView.showsUserLocation = YES; 
} 

-(IBAction)Directions:(id)sender; 
{ 
NSString *urlString = @"http://maps.apple.com/maps?daddr=33.3816566,-86.8415451"; 
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]]; 
} 

@end 

MapPin.h

#import <Foundation/Foundation.h> 
#import <MapKit/MapKit.h> 

@interface MapPin : NSObject <MKAnnotation> 
{ 
CLLocationCoordinate2D coordinate; 

NSString *title; 
NSString *subtitle; 
} 

@property (nonatomic, assign) CLLocationCoordinate2D coordinate; 
@property (nonatomic, copy) NSString *title; 
@property (nonatomic, copy) NSString *subtitle; 

@end 

MapPin.m

#import "MapPin.h" 

@implementation MapPin 

@synthesize coordinate, title, subtitle; 

@end 

感谢您的任何意见

+0

1.您不需要创建和设置要添加注释的区域。 setRegion方法只是定位地图。你可以直接使用'ann.coordinate = CLLocationCoordinate2DMake(lat,long);'来设置注释的坐标。 2. MKMapView并没有像Google Maps那样的“缩放级别”。您可以使用'MKCoordinateRegionMakeWithDistance'函数创建一个基于中心坐标中距离_meter_的区域。我认为这比一些缩放级别数字更方便和直观。 – Anna

回答