我的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)
您需要设置MKMapView的缩放级别。 好好看看这个: http://troybrant.net/blog/2010/01/set-the-zoom-level-of-an-mkmapview/