2017-06-07 93 views
0

我想在自定義座標上縮放MKMapView。所以我使用下面的代碼。MKMapView setRegion:導致應用在iOS SDK中崩潰

CLLocationCoordinate2D myCurrentLocationCordinate = CLLocationCoordinate2DMake(latitude, longtitude); 
[myMapView setCenterCoordinate:myCurrentLocationCordinate animated:YES]; 
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(myCurrentLocationCordinate, 500, 500); 
MKCoordinateRegion adjustedRegion = [myMapView regionThatFits:viewRegion]; 
[myMapView setRegion:adjustedRegion animated:YES]; 

但我的應用程序上setRegion:方法隨機崩潰。而得到這個日誌當它崩潰: -

adjustedRegion說明:(MKCoordinateRegion)adjustedRegion = {
中心=(緯度= 23.066432958888399,經度= 72.531898498535213)跨度=(latitudeDelta = 0.0051205743267423998,longitudeDelta = 0.0048793707173899747) }

有時也越來越以下錯誤: -

*終止應用程序由於未捕獲的異常 'NSGenericException', 原因: '(空)必須實現標題時canShowCallout是YES上 對應視圖>' *第一擲調用堆棧:(0x18e8b91b8 0x18d2f055c 0x19ab76244 0x19abb2c74 0x19ab74d44 0x19ab8db58 0x19477c7dc 0x19abb041c 0x19abb0290 0x19abb1588 0x1001ae010 0x1001ad318 0x101265258 0x101265218 0x101275080 0x101274b78 0x18d94b2a0 0x18d94ad8c) 的libC++ abi.dylib:與 型NSException

的未捕獲的異常終止我肯定不是爲什麼它是隨機崩潰。讓我知道是否有其他合適的解決方案來縮放自定義座標上的MKMapView

任何幫助,將不勝感激。

回答

2

我也得到了同樣的問題,但使用這種

CLLocationCoordinate2D startCoord = CLLocationCoordinate2DMake(latitudeAPI, longtitudeAPI); 
    [myMapView setRegion:MKCoordinateRegionMakeWithDistance(myCurrentLocationCordinate, 500.0, 500.0) animated:NO]; 

有沒有必要使用此行

MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(myCurrentLocationCordinate, 500, 500); 
MKCoordinateRegion adjustedRegion = [myMapView regionThatFits:viewRegion]; 

希望工程,並感謝@Firoze Lafeer幫助解決我解決這個問題。

2

我處理我的mapView縮放這種方式。你可以這樣試試嗎?

CLLocationCoordinate2D zoomLocation = CLLocationCoordinate2DMake(40.741168, 30.333555); 
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 0.5* 1609.344, 0.5* 1609.344); 

[self.myMapview setRegion:viewRegion animated:YES]; 
[self.myMapview setDelegate:self];