简体   繁体   中英

xcode ios objective-c mkmapview: compare MKMapView span

How can I compare the current span of a MKMapView? I am using the following code:

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{
    if ([[regionsMapView.region.span] doubleValue] < 1.0) {
        NSLog(@"SHOW ANNOTATIONS");
    }else {
        NSLog(@"HIDE ANNOTATIONS");
    }
}

But it shows error like this:

error: expected ':' before ']' token
confused by earlier errors, bailing out

And again if i use like below:

if (regionsMapView.region.span < 1.0) {
    NSLog(@"SHOW ANNOTATIONS");
}else {
    NSLog(@"HIDE ANNOTATIONS");
}

Then it also show error like below:

error: invalid operands to binary < (have 'MKCoordinateSpan' and 'double')

MKCoordinateSpan is a struct which has two values latitudeDelta and longitudeDelta , which looks like this,

typedef struct {

    CLLocationDegrees latitudeDelta;
    CLLocationDegrees longitudeDelta;

} MKCoordinateSpan;

If you want to compare any of there values. You should use,

if (regionsMapView.region.span.latitudeDelta < 1.0)

or,

if (regionsMapView.region.span.longitureDelta < 1.0)

remove the [] from [regionsMapView.region.span]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM