MKMapView setRegion:导致app在iOS SDK中崩溃

时间:2017-06-07 07:36:48

标签: ios objective-c mkmapview zooming

我想在自定义坐标上缩放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:方法上随机崩溃。并在崩溃时获取此日志: -

  

adjustRegion description:(MKCoordinateRegion)adjustedRegion = {
  center =(纬度= 23.066432958888399,经度=   72.531898498535213)span =(latitudeDelta = 0.0051205743267423998,longitudeDelta = 0.0048793707173899747)}

有时也会出现以下错误: -

  

*由于未捕获的异常'NSGenericException'而终止应用,   reason:'(null)必须在canShowCallout为YES时实现title   相应的视图>'   * 第一次抛出调用堆栈:(0x18e8b91b8 0x18d2f055c 0x19ab76244 0x19abb2c74 0x19ab74d44 0x19ab8db58 0x19477c7dc 0x19abb041c   0x19abb0290 0x19abb1588 0x1001ae010 0x1001ad318 0x101265258   0x101265218 0x101275080 0x101274b78 0x18d94b2a0 0x18d94ad8c)   libc ++ abi.dylib:以未捕获的类型异常终止   NSException

我肯定不是为什么它会随机崩溃。如果有任何其他适当的解决方案来缩放自定义坐标上的MKMapView,请告诉我。

任何帮助都将不胜感激。

2 个答案:

答案 0 :(得分: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 来帮助我解决这个问题。

答案 1 :(得分: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];