我想在后台进行地理定位!但我不能,我尝试了调度程序、线程、操作等……但我都阻止了进度条的进度。
问问题
1027 次
2 回答
2
我在这样的位置使用单例对象......
@implementation LocationManager
#pragma mark - singleton method
+ (LocationManager*)sharedInstance
{
static dispatch_once_t predicate = 0;
__strong static id sharedObject = nil;
dispatch_once(&predicate, ^{
sharedObject = [[self alloc] init];
});
return sharedObject;
}
#pragma mark - instance methods
-(id) init {
if (self = [super init]) {
_currentLocation = [[CLLocation alloc] init];
_locationManager = [[CLLocationManager alloc] init];
_locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
_locationManager.delegate = self;
}
return self;
}
- (void)start
{
[self.locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
//if the time interval returned from core location is more than two minutes we ignore it because it might be from an old session
if ( abs((int) [newLocation.timestamp timeIntervalSinceDate: [NSDate date]]) < 120) {
self.currentLocation = newLocation;
}
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
// [[[UIAlertView alloc] initWithTitle:@"Error" message:[error description] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
}
@end
那我只需要打电话...
[[LocationManager sharedInstance] start];
单身人士将开始跟踪位置。
比我打电话...
[[LocationManager sharedInstance] currentLocation];
对于当前位置。
然后,您可以使用它传递到 CLGeocoder 已经异步的方法中。
您不能依靠启动位置跟踪然后立即获得位置。您需要使用这样的方法。
于 2013-03-18T08:23:54.390 回答
0
CLGeocoder 在后台运行。
于 2013-03-18T09:01:48.013 回答