繁体   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