简体   繁体   中英

iOS Mapkit - SetRegion error

Could you point me what is wrong with this code?

-(void) showStoreRegion:(NSInteger)idx
{

    //StoreLocation* store = [self.listStore objectAtIndex:idx];

    //self.coordinate = CLLocationCoordinate2DMake(store.latitude,store.longitude);

    self.coordinate = CLLocationCoordinate2DMake(10.7500,106.6667);

    MKCoordinateRegion region;
    MKCoordinateSpan span;
    span.latitudeDelta  = 0.001;
    span.longitudeDelta = 0.001;

    region.span = span;
    region.center = self.coordinate;


    [theMapView setRegion:region animated:TRUE];
    [theMapView regionThatFits:region];


    [self addAnns];

} 

I got this message "terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid Region ' " when run this code/

You haven't initialised your region propertly. Try this

MKCoordinateSpan span = MKCoordinateSpanMake(0.001,0.001);
MKCoordinateRegion region = MKCoordinateRegionMake(self.coordinate, 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