MapKit专注于错误的地方

时间:2013-06-05 18:12:03

标签: ios mapkit

我有以下问题:我在mapkit中有anotations但是当我第一次打开地图时它没有进入预定位置。但它会在第二次打开时执行。这是我的代码中的问题吗?我在模拟器中没有这个问题,但是在手机上进行测试时就会发生这种情况。还有其他人遇到过这个问题吗?

很抱歉,如果代码太多了。感谢

#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

0 个答案:

没有答案