私の要件は、ユーザーの位置を追跡し、マップ ビューで複数の色で線を引くことです。このリンクからクレイグのコードを使用しています。彼のルートに注釈を 2 回追加しています。
- ユーザーの場所が変更されたとき (ここでは CSMapAnnotationTypeEnd を追加しています)。古い注釈を削除してから、新しい注釈を追加します。
- ユーザーが画面をダブルタップするたびに (ここでは CSMapAnnotationTypeImage を追加しています)。
新しい場所が見つかるたびに、マップ ビューが点滅します。この点滅は必要ありません。
しかし、私のアプリはクラッシュしています。これがクラッシュ レポートです。
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Triggered by Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x310ebf4e __exceptionPreprocess + 126
1 libobjc.A.dylib 0x3b4c46aa objc_exception_throw + 34
2 CoreFoundation 0x310eba4c __NSFastEnumerationMutationHandler + 124
3 MapKit 0x32284dfe -[MKAnnotationContainerView _updateAnnotationViewPerspective] + 238
4 MapKit 0x32284c3c -[MKNewAnnotationContainerView _updateAnnotationViewPerspective] + 56
5 MapKit 0x322b6962 -[MKMapView annotationManager:didAddAnnotationRepresentations:] + 42
6 MapKit 0x32280bc4 -[MKAnnotationManager updateVisibleAnnotations] + 1196
7 Foundation 0x31acfec8 __NSFireTimer + 60
8 CoreFoundation 0x310b70e2 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 10
9 CoreFoundation 0x310b6cfa __CFRunLoopDoTimer + 778
10 CoreFoundation 0x310b5096 __CFRunLoopRun + 1206
11 CoreFoundation 0x3101fce2 CFRunLoopRunSpecific + 518
12 CoreFoundation 0x3101fac6 CFRunLoopRunInMode + 102
13 GraphicsServices 0x35d4027e GSEventRunModal + 134
14 UIKit 0x338c1a3c UIApplicationMain + 1132
15 MyAppName 0x000845b8 main (main.m:16)
16 libdyld.dylib 0x3b9ccab2 tlv_initializer + 2
私の要件を達成するためのアイデアを誰かに教えてください。
注釈を追加および削除するためのコードを次に示します(新しい場所を取得したとき)。
for(CSMapAnnotation *annotation in _mapView.annotations){
if([annotation isEqual:annotationEnd]){
[_mapView removeAnnotation:annotationEnd];
annotationEnd = nil;
}
}
annotationEnd = [[CSMapAnnotation alloc] initWithCoordinate:[[pointsArray objectAtIndex:
([pointsArray count] - 1)] coordinate] annotationType:CSMapAnnotationTypeEnd title:@""];
[_mapView addAnnotation:annotationEnd];