天天看點

地圖定位出錯Exception : 'Invalid Region 1 今天做地圖定位,發現出現這個問題 ,調用以下函數,出現問題 Exception : 'Invalid Region <center:+inf, +0.00000000 span:+1.00000000, +0.50000000>' when trying to display the map

1 今天做地圖定位,發現出現這個問題 ,調用以下函數,出現問題

MKCoordinateRegion region = MKCoordinateRegionMake(_currentLocationCoordinate, MKCoordinateSpanMake(zoomLevel, zoomLevel));
   [_mapView setRegion:[_mapView regionThatFits:region] animated:YES];
           

Exception : 'Invalid Region <center:+inf, +0.00000000 span:+1.00000000, +0.50000000>' when trying to display the map

2 度娘了一下,原來是超出範圍了,加上範圍判斷

if ( (region.center.latitude >= -90) && (region.center.latitude <= 90) && (region.center.longitude >= -180) && (region.center.longitude <= 180) ){
        [_mapView setRegion:[_mapView regionThatFits:region] animated:YES];
    }
    else{
        NSLog(@"invilid region");
    }
           

3 究其根本,資料出錯,後來找了原因,latitude 118,錯了,已經超過範圍 -90<=latitude<=90 -180<=longtitude<=180