簡體   English   中英

MKMapView setRegion:導致應用程序在iOS SDK中崩潰

[英]MKMapView setRegion: causes app to crash in iOS SDK

我想在自定義坐標上縮放MKMapView 所以我用下面的代碼。

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: Method上隨機崩潰。 並在崩潰時獲取此日志:-

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

有時也會出現以下錯誤:-

*由於未捕獲的異常'NSGenericException'而終止應用程序,原因:'(null)必須在相應視圖上的canShowCallout為YES時實現標題>'*首次拋出調用堆棧:(0x18e8b91b8 0x18d2f055c 0x19ab76244 0x19abb2c74 0x19abcdd0d0x19abb110112581 0588 0x101275080 0x101274b78 0x18d94b2a0 0x18d94ad8c)libc ++ abi.dylib:以NSException類型的未捕獲異常終止

我確定不是為什么它隨機崩潰。 讓我知道是否有其他合適的解決方案可以在自定義坐標上縮放MKMapView

任何幫助,將不勝感激。

我也遇到了同樣的問題,但是使用這個解決了

 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幫助我解決了這個問題。

我以這種方式處理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];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM