だから私はiPhoneGPSのいくつかの精度の問題に取り組んでいます。ロケーションを利用したアプリがあります。
デリゲートメソッドでlocationManager: didUpdateToLocation: fromLocation:
、場所が返されます。少し調べてみると、desiredAccuracy
プロパティをに設定した場合でも、GPSが最初に返す結果が常に正確であるとは限らないようkCLLocationAccuracyBest
です。
これを回避するために、少なくとも3回stopUpdatingLocation
返される前に電話をかけませんnewLocation:
(これは非常に高速です)。またstopUpdatingLocation
、を返すかどうかについて、他の2つの「要件」を試してみましたnewLocation
。私が試した1つの方法は、緯度と経度を確認してnewLocation
比較しoldLocation
、これらが同一でない場合は、場所の更新を実行し続けることでした。また、oldLocation
との間の距離を確認してみましたがnewLocation
、20メートル未満であれば問題ありません。これらは両方とも、少なくとも3回の実行を返すことでテストされます。後者の方法は、ユーザーが移動中の車両に乗っている場合に100%同一であると逃げるのが非常に難しいため、それほど「厳密」ではnewLocation
ありoldLocation
ません。
さて、私の問題は、上記を行った場合でも(基本的に場所を受け入れず、いくつかの更新がCLLocationManager
行われ、CLLocations
(またはそれらが同一であるかどうか)間の距離をチェックするまで、場所について多少奇妙な結果が表示されることがありますが、テストするとき。
アプリを終了し、Maps.appにアクセスし、GPSを使用してマルチタスクを開き、アプリを強制終了してから再度開いてクリーンな起動を行うと、修正されることがあります。
同じ種類の問題を回避するために人々が使用した経験と可能な解決策はありますか?コメントと解決策を高く評価します:)
次のコードを取得したのがどのプロジェクトであったかは正確には覚えていませんが、これは非常にうまく機能しました(WWDC 2010ビデオからのものだったことを覚えています)。私のコードでは、元のプロジェクトからのコメントをそのまま残したので、これが役立つことを願っています。
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
// test the age of the location measurement to determine if the measurement is cached
// in most cases you will not want to rely on cached measurements
NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
if (locationAge > 5.0) return;
// test that the horizontal accuracy does not indicate an invalid measurement
if (newLocation.horizontalAccuracy < 0) return;
// test the measurement to see if it is more accurate than the previous measurement
if (bestEffortAtLocation == nil || bestEffortAtLocation.horizontalAccuracy > newLocation.horizontalAccuracy) {
// store the location as the "best effort"
self.bestEffortAtLocation = newLocation;
// test the measurement to see if it meets the desired accuracy
//
// IMPORTANT!!! kCLLocationAccuracyBest should not be used for comparison with location coordinate or altitidue
// accuracy because it is a negative value. Instead, compare against some predetermined "real" measure of
// acceptable accuracy, or depend on the timeout to stop updating. This sample depends on the timeout.
//
if (newLocation.horizontalAccuracy <= locationManager.desiredAccuracy) {
// we have a measurement that meets our requirements, so we can stop updating the location
//
// IMPORTANT!!! Minimize power usage by stopping the location manager as soon as possible.
//
[self stopUpdatingLocation:NSLocalizedString(@"Acquired Location", @"Acquired Location")];
// we can also cancel our previous performSelector:withObject:afterDelay: - it's no longer necessary
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(stopUpdatingLocation:) object:nil];
}
}
}
お役に立てれば!
GetLocationViewController.m
Appleの「LocateMe」サンプルプロジェクトのVia :
https://developer.apple.com/library/content/samplecode/LocateMe/Introduction/Intro.html
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加