在我目前的项目中。
我需要用户在50 meter
用户移动时的位置。
基本上在每次Objective c
更改后打开应用程序后,我需要{{1}}中的呼叫Web服务的用户位置。此外,我希望在应用程序处于后台状态时运行相同的进程。
提前致谢
答案 0 :(得分:2)
添加以下代码以获取用户的当前位置
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
现在添加一个名为didUpdateToLocation的CLLocationManagaer委托,并在其中添加以下代码。
CLLocationDistance米= [newLocation distanceFromLocation:oldLocation];
if(meters==50)
{
// CALL YOU WEBSERVICE
}
答案 1 :(得分:1)
在
中设置您的位置信息//create location manager object
locationManager = [[CLLocationManager alloc] init];
//there will be a warning from this line of code
[locationManager setDelegate:self];
//and we want it to be as accurate as possible
//regardless of how much time/power it takes
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
//set the amount of metres travelled before location update is made
[locationManager setDistanceFilter:50];
并添加
if ([CLLocationManager locationServicesEnabled]) {
[self.locationManager startUpdatingLocation];
}
<强>更新强>
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
CLLocation *location = locations.lastObject;
NSLog(@"%@", location.description);
//In here you get all details like
NSLog(@"latitude = %@",location.coordinate.latitude);
NSLog(@"longitude = %@",location.coordinate.longitude);
NSLog(@"altitude = %@",location.altitude);
NSLog(@"horizontalAccuracy = %@",location.horizontalAccuracy);
NSLog(@"verticalAccuracy = %@",location.verticalAccuracy);
NSLog(@"timestamp = %@",location.timestamp);
NSLog(@"speed = %@",location.speed);
NSLog(@"course = %@",location.course);
}