if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) {
[ZCUtility showNaviHelp:self];
}
- 应用从后台开启定位后应该重新定位并重新激活地图的定位模式
self.mapView.showsUserLocation = YES;
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(applicationActive) name:UIApplicationDidBecomeActiveNotification object:nil];
- (void)refreshLocation
{
self.isEnable = NO;
if (!self.locationManager) {
if ([CLLocationManager locationServicesEnabled]) {
// if location services are restricted do nothing
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusRestricted) {
// UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"Determining your current location cannot be performed at this time because location services are enabled but restricted." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
// [alertView show];
} else {
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers;
[self.locationManager setDistanceFilter:1000.0f];
self.locationManager.pausesLocationUpdatesAutomatically = NO;
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager performSelector:@selector(requestWhenInUseAuthorization) withObject:nil];
}
self.isEnable = YES;
}
} else {
// UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Determining your current location cannot be performed at this time because location services are not enabled." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
// [alertView show];
}
}
if (self.isEnable) {
self.locationManager.delegate = self;
[self.locationManager startUpdatingLocation];
} else {
//NSLog(@"Location services is not enabled");
}
}