简体   繁体   English

MKMapView setRegion:导致应用程序在iOS SDK中崩溃

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

I want to zoom MKMapView on custom coordinates. 我想在自定义坐标上缩放MKMapView So I using following code. 所以我用下面的代码。

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];

But my app is randomly crashing on setRegion: Method. 但是我的应用程序在setRegion: Method上随机崩溃。 And getting this log when it is crashing :- 并在崩溃时获取此日志:-

adjustedRegion description: (MKCoordinateRegion) adjustedRegion = { AdjustedRegion说明:(MKCoordinateRegion)AdjustedRegion = {
center = (latitude = 23.066432958888399, longitude = 72.531898498535213) span = (latitudeDelta = 0.0051205743267423998, longitudeDelta = 0.0048793707173899747) } 中心=(纬度= 23.066432958888399,经度= 72.531898498535213)跨度=(latitudeDelta = 0.0051205743267423998,经度Delta = 0.0048793707173899747)}

Also sometimes getting following error :- 有时也会出现以下错误:-

* Terminating app due to uncaught exception 'NSGenericException', reason: '(null) must implement title when canShowCallout is YES on corresponding view >' * First throw call stack: (0x18e8b91b8 0x18d2f055c 0x19ab76244 0x19abb2c74 0x19ab74d44 0x19ab8db58 0x19477c7dc 0x19abb041c 0x19abb0290 0x19abb1588 0x1001ae010 0x1001ad318 0x101265258 0x101265218 0x101275080 0x101274b78 0x18d94b2a0 0x18d94ad8c) libc++abi.dylib: terminating with uncaught exception of type NSException *由于未捕获的异常'NSGenericException'而终止应用程序,原因:'(null)必须在相应视图上的canShowCallout为YES时实现标题>'*首次抛出调用堆栈:(0x18e8b91b8 0x18d2f055c 0x19ab76244 0x19abb2c74 0x19abcdd0d0x19abb110112581 0588 0x101275080 0x101274b78 0x18d94b2a0 0x18d94ad8c)libc ++ abi.dylib:以NSException类型的未捕获异常终止

I am sure not why it is crashing randomly. 我确定不是为什么它随机崩溃。 Let me know if any other proper solution for zooming the MKMapView on custom coordinates. 让我知道是否有其他合适的解决方案可以在自定义坐标上缩放MKMapView

Any help would be appreciated. 任何帮助,将不胜感激。

I also got the same issue, but solved using this 我也遇到了同样的问题,但是使用这个解决了

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

There is no need to use this line 无需使用此行

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

Hope it works and thanks to @Firoze Lafeer to help me to solve this. 希望它能工作,并感谢@Firoze Lafeer帮助我解决了这个问题。

I handle my mapView zoom this way. 我以这种方式处理mapView缩放。 Could you try it this way? 你能这样尝试吗?

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