(とりわけ) いくつかの位置データを含むクラス インスタンスを作成するアプリケーションがあります。
アプリ デリゲートで位置情報サービスを設定し、位置データの取得を開始します。
//Delegate method to receive location information from locationManager
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
latestLocation = newLocation;//Make latest location the same as NewLocation
NSLog(@"Location is: %@", latestLocation);
}
別のクラスから CLLocation インスタンスを取得できるように、最新の場所をプロパティとして宣言します。
私のキャプチャクラスは、呼び出されたときに、init メソッドが呼び出されたときに CLLocation を取得します。
//Designated initialiser
-(id) initWithVideoPath:(NSString *) vPath
userNotes:(NSString *) uNotes
retentionState:(NSString *) rState
{
//Call the super classes designated initializer
[super init];
//Get a pointer to the application delegate so we can access the location props
Rolling_VideoAppDelegate *appDelegate = (Rolling_VideoAppDelegate*)[UIApplication sharedApplication].delegate;
//If superclass failed to init
if (!self)
return nil;
//Give the variables some initial values
[self setVideoPath:vPath];
[self setUserNotes:uNotes];
[self setRetentionState:rState];
dateCreated = [[NSDate alloc] init];
mp = [[MapPoint alloc]initWithCoordinate:[[appDelegate latestLocation]coordinate]];//get the location from the coords from appDelegate
return self;
[dateCreated release];
}
ただし、mapPoint init が呼び出されるとアプリがクラッシュします。問題は、CLLocation 情報を正しく取得していないことです。