2014-05-16 50 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

回答