ユーザーの正確な緯度/経度座標を見つけようとしています。ドキュメントを参照したところ、LocateMe サンプル プロジェクトについて知りました。位置情報が正確かどうかをユーザーに知らせるアラートがポップアップするように、コードを編集しようとしています。
私は以下のコードを持っていますが、アラートは常にユーザーの位置情報が不正確であると言っています (「場所が悪い」)。誰かが私が間違っていることを知っていますか?
Apple のサンプル コードに次の行が含まれていることに気付きました。[setupInfo setObject:[NSNumber numberWithDouble:kCLLocationAccuracyHundredMeters] forKey:kSetupInfoKeyAccuracy];
以下のコードをどのように編集してkCLLocationAccuracyNearestTenMeters
. 可能であれば、別のビュー コントローラーを参照する必要はなく、メソッドに直接含めることができるようにしたいと考えています。
どんな助けでも素晴らしいでしょう。ありがとうございました!
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation
*)newLocation fromLocation:(CLLocation *)oldLocation {
//CAN I PUT THE DESIRED ACCURACY HERE?
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationMeasurements addObject:newLocation];
NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
if (locationAge > 5.0) return;
if (newLocation.horizontalAccuracy < 0) return;
if (bestEffortAtLocation == nil || bestEffortAtLocation.horizontalAccuracy >
newLocation.horizontalAccuracy) {
self.bestEffortAtLocation = newLocation;
if (newLocation.horizontalAccuracy <= locationManager.desiredAccuracy) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Location Good"
message:@"OK" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil,
nil];
[alert show];
return;
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Location Bad"
message:@"OK" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil,
nil];
[alert show];
return;
}
}
}