次のコードで cllocation manage を設定しました。オープンエリアで活躍します。しかし、地下鉄や地下街に入った後、私の電話はデータを受信できません(すべてのデータが0でした)。
地下鉄でもアプリを動作させたい場合はどうすればよいですか? startMonitoringSignificantLocationChanges/startMonitoringForRegion メソッドを標準の位置更新メソッドと統合する必要はありますか? もしそうなら、どうやって作るのですか?
初期化メソッドで
locationManager=[[CLLocationManager alloc]init];
locationManager.desiredAccuracy=kCLLocationAccuracyBest;
locationManager.distanceFilter=kCLDistanceFilterNone;
locationManager.delegate=self;
[locationManager startUpdatingLocation];
cllocation デリゲート メソッドで
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
NSLog(@"%@",newLocation);
NSDate*eventDate=newLocation.timestamp;
NSTimeInterval howRecent=abs([eventDate timeIntervalSinceNow]);
if ((newLocation.coordinate.latitude != oldLocation.coordinate.latitude)&&(newLocation.coordinate.longitude != oldLocation.coordinate.longitude)) {
locationChanged=YES;
}else{
locationChanged=NO;
}
if ((howRecent <5.0)&&
((newLocation.horizontalAccuracy<(oldLocation.horizontalAccuracy -10.0))||
(newLocation.horizontalAccuracy<50.0)||
((newLocation.horizontalAccuracy<=120)&& locationChanged))) {
self.myLocation=[newLocation copy];
// NSLog(@"mylocation==%@",[self.myLocation description]);
}
//location info draw from plist
CLLocation *targetLocation = [[CLLocation alloc] initWithLatitude:Target_LAT longitude:Target_LONG];
double distance = [self.myLocation distanceFromLocation:targetLocation]/1000;
NSString*distString=[NSString stringWithFormat:@"%0.2f km",distance];
[delegate getLocationUpdate:self.myLocation distanceUpdate:distString];
//In this testing app, I use delegate to take cllocation data. Then those datas display in view controller.
}