実行をマップするのと同様に、ルートを構築して保存するアプリケーションを構築しようとしています。私はBreadcrumbサンプル コードを使用しています。具体的にCrumbPath
はCrumbPathView
、ルートのベースとして Apple から提供されています。2 つの質問:
のような
MKMapPoint *points
オブジェクトにアクセスしようとすると:CrumbPath
[_route lockForReading]; NSLog(@"%@", _route.points); NSLog(@"%d", _route.pointCount); [_route unlockForReading];
次のように言って、アプリがクラッシュします。
Thread 1: EXC_BAD_ACCESS (code: 1, address: 0x9450342d)
CrumbPath.m
ファイル内で、アップルの人々は明示的に書き込みロックを取得してからロックを解除することで「配列」に書き込みますが、読み取りロックを取得してそこから読み取ろうとすると、それを理解するのに苦労します。クラッシュします。にアクセスしようとする理由
points
は、 を取得してオブジェクトにMKMapPoints
変換し、保存して、ユーザーの要求に応じて を再描画できるようにするためです。にアクセスできないため、 からに送信したオブジェクトを配列に保存して、 Parseバックエンドにアップロードしようとしましたが、常に次のようなエラーが表示されます。CLLocationCoordinate2D
polyline
points
CLLocationCoordinate2D
locationManager
_route
Sending 'CLLocationCoordinate2D' to parameter of incompatible type 'id'
これはこれを簡単にするものではありません。これらのエラーが発生する理由について誰かが洞察を持っていますか?
ロケーションマネージャーデリゲート
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
if (_userLocation.longitude != manager.location.coordinate.longitude
&& _userLocation.latitude != manager.location.coordinate.latitude) {
_userLocation = manager.location.coordinate;
}
if (_isRecording) {
if (!_route) {
NSLog(@"lat: %f, lng: %f", _userLocation.latitude, _userLocation.longitude);
_route = [[CrumbPath alloc] initWithCenterCoordinate:_userLocation];
[_mapView addOverlay:_route];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(_userLocation, 2000, 2000);
[_mapView setRegion:region animated:YES];
}else {
MKMapRect updateRect = [_route addCoordinate:_userLocation];
if (!MKMapRectIsNull(updateRect)) {
MKZoomScale currentZoomScale = (CGFloat)(_mapView.bounds.size.width / _mapView.visibleMapRect.size.width);
CGFloat lineWidth = MKRoadWidthAtZoomScale(currentZoomScale);
updateRect = MKMapRectInset(updateRect, -lineWidth, -lineWidth);
[_routeView setNeedsDisplayInMapRect:updateRect];
}
}
[_routePoints addObject:_userLocation];
[_route lockForReading];
NSLog(@"%d", _route.pointCount);
NSLog(@"%@", _route.points);
[_route unlockForReading];
}
}
ロジックの記録を停止
//stop recording
NSLog(@"STOP");
if (_route) {
NSLog(@"There is a route");
//Show route options toolbar
[_route lockForReading];
NSLog(@"%@", _route);
NSLog(@"%d", _route.pointCount);
NSLog(@"%@", _route.points);
PFObject *routeToSave = [PFObject objectWithClassName:@"Routes"];
//[routeToSave setObject:_route forKey:@"routePoints"];
[_route unlockForReading];
[routeToSave saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
NSLog(@"%c", succeeded);
}else {
NSLog(@"%@", error);
}
}];
}