I'm working with MKMapKit and setting the region to be a full size United States and it's displaying as expected. However when inspecting the self.mapView.region
property I'm getting some weird results that are affecting my calculations later in the program.
Here is how I'm setting up the map view:
- (void)viewDidLoad
{
[super viewDidLoad];
MKCoordinateRegion usa = MKCoordinateRegionMake(CLLocationCoordinate2DMake(39.4, -91.5), MKCoordinateSpanMake(40, 40));
self.mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:self.mapView];
self.mapView.region = usa;
self.mapView.delegate = self;
self.mapView.showsUserLocation = YES;
[self.mapView.userLocation addObserver:self forKeyPath:@"location" options:0 context:nil];
}
This is the USA MKCoordinateRegion
, looks fine and works:
(lldb) p usa
(MKCoordinateRegion) $0 = {
(CLLocationCoordinate2D) center = {
(CLLocationDegrees) latitude = 39.4
(CLLocationDegrees) longitude = -91.5
}
(MKCoordinateSpan) span = {
(CLLocationDegrees) latitudeDelta = 40
(CLLocationDegrees) longitudeDelta = 40
}
}
Then I set the region self.mapView.region = usa;
and break after it, this is now the output of the self.mapView.region
.
(lldb) p [self.mapView region]
(MKCoordinateRegion) $1 = {
(CLLocationCoordinate2D) center = {
(CLLocationDegrees) latitude = 39.4
(CLLocationDegrees) longitude = 39.4
(CLLocationDegrees) latitudeDelta = 39.4
(CLLocationDegrees) longitudeDelta = -91.5
}
(MKCoordinateSpan) span = {
(CLLocationDegrees) latitude = 66.4999527377778
(CLLocationDegrees) longitude = 66.4999527377778
(CLLocationDegrees) latitudeDelta = 66.4999527377778
(CLLocationDegrees) longitudeDelta = 67.4999957172512
}
(CLLocationCoordinate2D) center = {}
}
So the problem is the center struct is wrong, the longitude is off and CLLocationCoordinate2D
shouldn't even have delta fields, it looks like a MKCoordinateSpan
.
CLLocationCoordinate2D definition:
typedef struct {
CLLocationDegrees latitude;
CLLocationDegrees longitude;
} CLLocationCoordinate2D;
So any idea where I'm going wrong? Am I missing something blazingly obvious? If this is the wrong way to do it, how can I get the true data to do some calculations later in the app?
Using xcode 4.6.1 and iOS 6.1 simulator.
I think this is just an lldv bug or an error in my lldb usage. If I NSLog the lat/lon everything is fine.