1

我有以下问题:我的 mapkit 中有注释,但是当我第一次打开地图时,它并没有转到预定义的位置。但是,它确实会在第二次打开时执行。这是我的代码中的问题吗?我在模拟器中没有这个问题,但是在手机上测试时会发生。有没有其他人遇到过这个问题?

对不起,如果这是太多的代码。谢谢

#import "MapViewController.h"
#import "Annotation.h"

@interface MapViewController ()

@end

//EDINBURGH Kilt Store Coordinates
#define EDI_LATITUDE 55.945984;
#define EDI_LONGITUDE -3.220979;

//MUSSELBURGH Kilt Store Coordinates
#define MUSS_LATITUDE 55.943748;
#define MUSS_LONGITUDE -3.058187;

//DALKEITH Kilt Store Coordinates
#define DAL_LATITUDE 55.883271;
#define DAL_LONGITUDE -3.083474;

//DUNDEE Kilt Store Coordinates
#define DUN_LATITUDE 56.459118;
#define DUN_LONGITUDE -2.97124;

//Span
#define THE_SPAN 0.10f;


@implementation MapViewController
@synthesize myMapView;

- (void)viewDidLoad
{
    [super viewDidLoad];
    //Create the region
    MKCoordinateRegion myRegion;

    //Center
    CLLocationCoordinate2D center;
    center.latitude = EDI_LATITUDE;
    center.longitude = EDI_LONGITUDE;

    //Span
    MKCoordinateSpan span;
    span.latitudeDelta = THE_SPAN;
    span.longitudeDelta = THE_SPAN;

    myRegion.center = center;
    myRegion.span = span;

    //Set our mapView
    [myMapView setRegion:myRegion animated:YES];

    //Annotation
    NSMutableArray * locations = [[NSMutableArray alloc] init];
    CLLocationCoordinate2D location;
    Annotation * myAnn;

    //Edinburgh Annotation
    myAnn = [[Annotation alloc] init];
    location.latitude = EDI_LATITUDE;
    location.longitude = EDI_LONGITUDE;
    myAnn.coordinate = location;
    myAnn.title = @"The Kilt Store";
    myAnn.subtitle= @"Haymarket";
    [locations addObject:myAnn];

    //Musselburgh Annotation
    myAnn = [[Annotation alloc] init];
    location.latitude = MUSS_LATITUDE;
    location.longitude = MUSS_LONGITUDE;
    myAnn.coordinate = location;
    myAnn.title = @"The Kilt Store";
    myAnn.subtitle= @"Musselburgh";
    [locations addObject:myAnn];

    //Musselburgh Annotation
    myAnn = [[Annotation alloc] init];
    location.latitude = DAL_LATITUDE;
    location.longitude = DAL_LONGITUDE;
    myAnn.coordinate = location;
    myAnn.title = @"The Kilt Store";
    myAnn.subtitle= @"Dalkeith";
    [locations addObject:myAnn];

    //Dundee Annotation
    myAnn = [[Annotation alloc] init];
    location.latitude = DUN_LATITUDE;
    location.longitude = DUN_LONGITUDE;
    myAnn.coordinate = location;
    myAnn.title = @"The Kilt Store";
    myAnn.subtitle= @"Dundee";
    [locations addObject:myAnn];

     [self.myMapView addAnnotations:locations];
}

- (void)viewDidUnload
{
    [self setMyMapView:nil];
    [super viewDidUnload];
    //Release any retained subview
}

@end
4

0 回答 0