MKMapView 通过 setRegion 崩溃

问题描述 投票:0回答:1

我想在地图上显示特定地址。这是我的代码。

- (void)viewDidLoad{
[super viewDidLoad];

CLLocationCoordinate2D startCoord = CLLocationCoordinate2DMake(51.514302, 7.616798);
MKCoordinateRegion adjustedRegion = [_map regionThatFits:MKCoordinateRegionMakeWithDistance(startCoord, 200.0, 200.0)];
adjustedRegion.span = MKCoordinateSpanMake(0.005, 0.005);

[_map setRegion:adjustedRegion];

在模拟器上它工作正常,但在我的 iPad 上它崩溃了...... 我的错在哪里?

Last Exception Backtrace:
0   CoreFoundation                  0x33cbe3e2 __exceptionPreprocess + 158
1   libobjc.A.dylib                 0x3bb4e95e objc_exception_throw + 26
2   CoreFoundation                  0x33cbe0d0 -[NSException raise] + 4
3   MapKit                          0x34aec530 -[MKMapView setRegion:animated:] + 672
4   MapKit                          0x34aec64a __32-[MKMapView setRegion:animated:]_block_invoke_0 + 90
5   MapKit                          0x34ad6006 -[MKMapView _updateCenteredAttributesWithCoordinate:] + 122
6   MapKit                          0x34ad5f3a -[MKMapView _sizeDidChangeWithCenterCoordinate:] + 126
7   MapKit                          0x34ae8b58 -[MKMapView setBounds:] + 224
8   UIKit                           0x35cb2476 -[UIView(Geometry) _applyISEngineLayoutValues] + 246
9   UIKit                           0x35b3068a -[UIView(Geometry) _resizeWithOldSuperviewSize:] + 138
10  CoreFoundation                  0x33cb9c1c __NSArrayChunkIterate + 364
11  CoreFoundation                  0x33cb2bb2 __NSArrayEnumerate + 590
12  CoreFoundation                  0x33c14e32 -[NSArray enumerateObjectsWithOptions:usingBlock:] + 58
13  UIKit                           0x35ae9096 -[UIView(Geometry) resizeSubviewsWithOldSize:] + 114
14  UIKit                           0x35f09da8 -[UIView(AdditionalLayoutSupport) _is_layout] + 112
15  UIKit                           0x35ad6ae0 -[UIView(Hierarchy) layoutSubviews] + 68
16  UIKit                           0x35ad08c2 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 254
17  QuartzCore                      0x3587c50e -[CALayer layoutSublayers] + 210
18  QuartzCore                      0x3587c0b0 CA::Layer::layout_if_needed(CA::Transaction*) + 456
19  QuartzCore                      0x358aaeca -[CALayer layoutIfNeeded] + 138
20  UIKit                           0x35b7a0dc -[UIViewController window:setupWithInterfaceOrientation:] + 204
21  UIKit                           0x35b792c6 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 3598
22  UIKit                           0x35b784aa -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 42
23  UIKit                           0x35b78434 -[UIWindow _setRotatableViewOrientation:duration:force:] + 64
24  UIKit                           0x35cadcb4 __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke_0 + 100
25  UIKit                           0x35b3667e -[UIWindow _updateToInterfaceOrientation:duration:force:] + 214
26  UIKit                           0x35b363c2 -[UIWindow setAutorotates:forceUpdateInterfaceOrientation:] + 690
27  UIKit                           0x35b35d2a -[UIViewController _tryBecomeRootViewControllerInWindow:] + 150
28  UIKit                           0x35b2ce86 -[UIWindow addRootViewControllerViewIfPossible] + 366
29  UIKit                           0x35b28af0 -[UIWindow _setHidden:forced:] + 360
30  UIKit                           0x35b6a1dc -[UIWindow makeKeyAndVisible] + 56
31  UIKit                           0x35b2d7fe -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1642
32  UIKit                           0x35b2582e -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 694
33  UIKit                           0x35acdd1a -[UIApplication handleEvent:withNewEvent:] + 1006
34  UIKit                           0x35acd7a8 -[UIApplication sendEvent:] + 68
35  UIKit                           0x35acd1ea _UIApplicationHandleEvent + 6194
36  GraphicsServices                0x377c05f2 _PurpleEventCallback + 586
37  GraphicsServices                0x377c0222 PurpleEventCallback + 30
38  CoreFoundation                  0x33c933e2 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 30
39  CoreFoundation                  0x33c93386 __CFRunLoopDoSource1 + 134
40  CoreFoundation                  0x33c9220a __CFRunLoopRun + 1378
41  CoreFoundation                  0x33c05238 CFRunLoopRunSpecific + 352
42  CoreFoundation                  0x33c050c4 CFRunLoopRunInMode + 100
43  UIKit                           0x35b24468 -[UIApplication _run] + 664
44  UIKit                           0x35b212b4 UIApplicationMain + 1116
45  AD HOK                          0x000bcd80 main (main.m:16)
46  libdyld.dylib                   0x3bf7bb1c start + 0


Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libsystem_kernel.dylib          0x3c042350 __pthread_kill + 8
1   libsystem_c.dylib               0x3bfb8fb2 pthread_kill + 54
2   libsystem_c.dylib               0x3bff5366 abort + 90
3   libc++abi.dylib                 0x3b59ddda abort_message + 70
4   libc++abi.dylib                 0x3b59b094 _ZL17default_terminatev + 20
5   libobjc.A.dylib                 0x3bb4ea58 _ZL15_objc_terminatev + 144
6   libc++abi.dylib                 0x3b59b118 _ZL19safe_handler_callerPFvvE + 76
7   libc++abi.dylib                 0x3b59b1b0 std::terminate() + 16
8   libc++abi.dylib                 0x3b59c626 __cxa_rethrow + 90
9   libobjc.A.dylib                 0x3bb4e9b0 objc_exception_rethrow + 8
10  CoreFoundation                  0x33c0529c CFRunLoopRunSpecific + 452
11  CoreFoundation                  0x33c050c4 CFRunLoopRunInMode + 100
12  UIKit                           0x35b24468 -[UIApplication _run] + 664
13  UIKit                           0x35b212b4 UIApplicationMain + 1116
14  AD HOK                          0x000bcd80 main (main.m:16)
15  libdyld.dylib                   0x3bf7bb1c start + 0

Thread 1:
0   libsystem_kernel.dylib          0x3c042d98 __workq_kernreturn + 8
1   libsystem_c.dylib               0x3bf90ad6 _pthread_workq_return + 14
2   libsystem_c.dylib               0x3bf907f2 _pthread_wqthread + 362
3   libsystem_c.dylib               0x3bf90680 start_wqthread + 4

Thread 2 name:  Dispatch queue: com.apple.libdispatch-manager
Thread 2:
0   libsystem_kernel.dylib          0x3c0325d0 kevent64 + 24
1   libdispatch.dylib               0x3bf6dd22 _dispatch_mgr_invoke + 806
2   libdispatch.dylib               0x3bf69374 _dispatch_mgr_thread + 32

Thread 3:
0   libsystem_kernel.dylib          0x3c042d98 __workq_kernreturn + 8
1   libsystem_c.dylib               0x3bf90ad6 _pthread_workq_return + 14
2   libsystem_c.dylib               0x3bf907f2 _pthread_wqthread + 362
3   libsystem_c.dylib               0x3bf90680 start_wqthread + 4

Thread 4 name:  WebThread
Thread 4:
0   libsystem_kernel.dylib          0x3c031e30 mach_msg_trap + 20
1   libsystem_kernel.dylib          0x3c031fd0 mach_msg + 48
2   CoreFoundation                  0x33c932b6 __CFRunLoopServiceMachPort + 126
3   CoreFoundation                  0x33c9202c __CFRunLoopRun + 900
4   CoreFoundation                  0x33c05238 CFRunLoopRunSpecific + 352
5   CoreFoundation                  0x33c050c4 CFRunLoopRunInMode + 100
6   WebCore                         0x39be0390 _ZL12RunWebThreadPv + 440
7   libsystem_c.dylib               0x3bf9b0de _pthread_start + 306
8   libsystem_c.dylib               0x3bf9afa4 thread_start + 4

Thread 5:
0   libsystem_kernel.dylib          0x3c042d98 __workq_kernreturn + 8
1   libsystem_c.dylib               0x3bf90ad6 _pthread_workq_return + 14
2   libsystem_c.dylib               0x3bf907f2 _pthread_wqthread + 362
3   libsystem_c.dylib               0x3bf90680 start_wqthread + 4

Thread 0 crashed with ARM Thread State (32-bit):
    r0: 0x00000000    r1: 0x00000000      r2: 0x00000000      r3: 0x3db31524
    r4: 0x00000006    r5: 0x3db31b78      r6: 0x210aa354      r7: 0x2fd459d4
    r8: 0x210aa330    r9: 0x00000300     r10: 0x00000000     r11: 0x7ff80000
    ip: 0x00000148    sp: 0x2fd459c8      lr: 0x3bfb8fb7      pc: 0x3c042350
  cpsr: 0x00000010
ios objective-c xcode mkmapview
1个回答
4
投票

当您最终再次明确设置该区域的跨度时,尚不清楚为什么您要向地图询问适合的区域。此外,在布局完成之前,地图对这个问题没有有意义的答案。这可能就是它崩溃的原因,因为该区域没有正确定义。

从您的代码来看,您似乎只是想这样做:

- (void)viewDidLoad{
   [super viewDidLoad];

   CLLocationCoordinate2D startCoord = CLLocationCoordinate2DMake(51.514302, 7.616798);
   [_map setRegion:MKCoordinateRegionMakeWithDistance(startCoord, 200.0, 200.0) animated:NO];
}

我认为这更简单,并且应该可以在设备上正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.