2012-05-03 14 views
0

CLLocationのアップデートを取得するたびにLatとLongを記録する非常に基本的なiPhoneアプリケーションを作成しました。これらの新しいポジションをGPXファイルに保存します。これをルートオーバーレイとしてGoogleマップにロードできます。ズームアウトすると、ルートはかなり正確に見えますが、ズームインすると、私のルートは実際に運転していた道路の横に表示されることがよくあります。これの典型的な例の1つは、私が交差点に近づくにつれて位置の更新が起こり、次に角を曲がった後に再び行われるということです。 2つのポイントが接続されていると、私は道を離れるように見えます。この精度を向上させる方法があるのか​​、ルートを実際の道路にスナップするのか誰にでも分かりますか?次のようにiPhoneの正確な位置コアの位置と長さ

更新のための私のコードは次のとおりです。私の問題を見ているため

- (void)locationUpdate:(CLLocation *)location 
{ 
//////////////////////////////////////////////////////// 
//Write to File 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *testFile = [documentsDirectory stringByAppendingPathComponent:@"routeplots.gpx"]; 

    BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:testFile]; 

    if(fileExists) { 
     // get a handle to the file 

     NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:testFile]; 

     // move to the end of the file 
     [fileHandle seekToEndOfFile]; 

     NSString *data =[NSString stringWithFormat:@"\n<trkpt lat='%f' lon='%f'><name>%f</name></trkpt>", location.coordinate.latitude , location.coordinate.longitude , [location speed]]; 

     // move to the end of the file 
     [fileHandle seekToEndOfFile]; 

     // convert the string to an NSData object 
     NSData *textData = [data dataUsingEncoding:NSUTF8StringEncoding]; 

     // write the data to the end of the file 
     [fileHandle writeData:textData]; 

     // clean up 
     [fileHandle closeFile]; 
} 
} 

おかげで、ジェームズ

+0

[this](http://stackoverflow.com/questions/1081219/optimizing-cllocationmanager-corelocation-to-retrieve-data-points-faster-on-the) –

+0

desireAccuracyとdistanceFilterを設定しましたか? ?これを試していない場合: locationManager.desiredAccuracy = kCLLocationAccuracyBest; locationManager.distanceFilter = kCLDistanceFilterNone; – peko

答えて

1

はAccuracyBestにdesiredAccuracyを設定します。 locationManager.desiredAccuracy = KCLLocationAccuracyBest。

+0

これをお寄せいただきありがとうございます。私はこれらの値を変更して比較する方法を検討します。 –

1

あなたがやっていることのためにAPPLE自体が提供するsample applicationをご覧ください。デバイスにサンプルインストールをダウンロードして、どのように動作しているかを知るだけです。

It Demonstrates how to draw a path using the Map Kit overlay, MKOverlayView, that follows and tracks the user's current location. The included CrumbPath and CrumbPathView overlay and overlay view classes can be used for any path of points that are expected to change over time. It also demonstrates what is needed to track the user's location as a background process.

はそれがお役に立てば幸いです。

+0

おかげさしで、Jennisさんは有望ですね。御時間ありがとうございます。乾杯、J –

関連する問題