1

コアの位置とコアデータについて質問したいです。私はいくつかの質問を見ましたが、それを行うことができませんでした..いくつかのテキストフィールド、写真、日付と時刻のデータをUITableViewに保存するアプリケーションがありますコアデータを使用して、すべてを保存しました(写真、テキスト、日付など)位置データを保存しようとしていますiできませんでした。

これは私のコードの一部です。

    #pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];

    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;

    [locationManager startUpdatingLocation];

    NSDateFormatter *myFormatter = [[NSDateFormatter alloc] init];
    [myFormatter setDateFormat:@"MM-dd-yyyy HH:mm"];
    [myFormatter setTimeZone:[NSTimeZone systemTimeZone]];

    todaysDate = [myFormatter stringFromDate:[NSDate date]];
    myDateLabel.text = todaysDate;

    UIView *patternBg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    patternBg.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background01.png"]];
    self.tableView.backgroundView = patternBg;

    // If we are editing an existing picture, then put the details from Core Data into the text fields for displaying

    if (currentPicture)
    {
        [companyNameField setText:[currentPicture companyName]];
        [myDateLabel setText:[currentPicture currentDate]];

        if ([currentPicture photo])
            [imageField setImage:[UIImage imageWithData:[currentPicture photo]]];
    }
}

保存ボタンで

    - (IBAction)editSaveButtonPressed:(id)sender
{
    // For both new and existing pictures, fill in the details from the form
    [self.currentPicture setCompanyName:[companyNameField text]];
    [self.currentPicture setCurrentDate:[myDateLabel text]];
    [self.currentPicture setCurrentTime:[myTimeLabel text]];
    [self.currentPicture setLatitudeData:[_latitudeLabel text]];
    [self.currentPicture setLongtidueData:[_longtitudeLabel text]];

}

最後に、私の locationManager のメソッド..

    - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    NSLog(@"didUpdateToLocation: %@", newLocation);
    CLLocation *currentLocation = newLocation;

    if (currentLocation != nil) {
        _longtitudeLabel.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
        _latitudeLabel.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];
         [self->locationManager stopUpdatingLocation];
    }


}

「[locationmanager stopUpdatingLocation];」を試しました 何度もですが、アプリに入ると、コードが緯度と経度のデータの計算を開始し、そのデータを1回だけ取得して保存したい..

ありがとう!

4

3 に答える 3

0

呼び出しstopUpdatingLocationによって位置情報の更新が停止しない場合、ほとんどの場合self->locationManagernil です。それは、あなたが実際に電話をかけていないことを意味します。

コードが宣言によって暗示されるセマンティクスを使用しないことを強調しているように見えることを除いて、これが発生する理由を正確に確認することは困難です。in に@property代入するだけで宣言が回避され、使用してマネージャーを検索することも同様に回避されます。それがプロパティであると仮定すると、それを に割り当て、それを検索するときにも使用する必要があります。locationviewDidLoadself->locationManagerlocationself.locationManager

于 2013-05-03T16:13:01.263 に答える
0

いくつかのこと:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
    if (locationAge > 5) return;  // ignore cached location, we want current loc

    if (newLocation.horizontalAccuracy <= 0) return;  // ignore invalid

    // wait for GPS accuracy (will be < 400)
    if (newLocation.horizontalAccuracy < 400) {
        _longtitudeLabel.text = [NSString stringWithFormat:@"%.8f", newLocation.coordinate.longitude];
        _latitudeLabel.text = [NSString stringWithFormat:@"%.8f", newLocation.coordinate.latitude];
         [manager stopUpdatingLocation];
    }    
}
于 2013-05-03T16:31:39.620 に答える