Note that there are some explanatory texts on larger screens.

plurals
  1. POMKMapView region property returning bad struct
    primarykey
    data
    text
    <p>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 <code>self.mapView.region</code> property I'm getting some weird results that are affecting my calculations later in the program.</p> <p>Here is how I'm setting up the map view:</p> <pre><code>- (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]; } </code></pre> <p>This is the USA <code>MKCoordinateRegion</code>, looks fine and works:</p> <pre><code>(lldb) p usa (MKCoordinateRegion) $0 = { (CLLocationCoordinate2D) center = { (CLLocationDegrees) latitude = 39.4 (CLLocationDegrees) longitude = -91.5 } (MKCoordinateSpan) span = { (CLLocationDegrees) latitudeDelta = 40 (CLLocationDegrees) longitudeDelta = 40 } } </code></pre> <p>Then I set the region <code>self.mapView.region = usa;</code> and break after it, this is now the output of the <code>self.mapView.region</code>.</p> <pre><code>(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 = {} } </code></pre> <p>So the problem is the center struct is wrong, the longitude is off and <code>CLLocationCoordinate2D</code> shouldn't even have delta fields, it looks like a <code>MKCoordinateSpan</code>.</p> <p>CLLocationCoordinate2D definition:</p> <p><code>typedef struct { CLLocationDegrees latitude; CLLocationDegrees longitude; } CLLocationCoordinate2D;</code></p> <p>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?</p> <p>Using xcode 4.6.1 and iOS 6.1 simulator.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload