MapViewController始终显示当前位置的视图

时间:2014-07-25 10:10:50

标签: ios objective-c ios7 ios5 ios6

我编写了以下代码,例如:

但我总是指向我当前的位置。我该如何解决这个问题?

 MapViewController *mvc = [[MapViewController alloc] initWithNibName:@"MapViewController" bundle:nil];

CLLocationCoordinate2D annotationCoord;

annotationCoord.latitude = 47.640071;
annotationCoord.longitude = -122.129598;

MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
annotationPoint.coordinate = annotationCoord;
annotationPoint.title = @"Microsoft";
annotationPoint.subtitle = @"Microsoft's headquarters";
[mvc.mapView addAnnotation:annotationPoint];

注:

MapViewcontroller.h

@interface MapViewController : UIViewController <MKMapViewDelegate>
@property (weak, nonatomic) IBOutlet MKMapView *mapView;
@end

MapViewController.m

@implementation MapViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    self.mapView.delegate = self;
    self.mapView.mapType = MKMapTypeStandard;

    self.mapView.showsUserLocation = YES;


}

1 个答案:

答案 0 :(得分:0)

在代码下方试试

 MKCoordinateRegion adjustedRegion = [mapView regionThatFits:MKCoordinateRegionMakeWithDistance(annotationCoord, 200, 200)];
[mapView setRegion:adjustedRegion animated:YES];

可能会全力以赴..干杯......