2012-06-17 37 views

回答

2

它應該會自動出現一次,實際上需要的位置跟蹤被調用的代碼(當彈出首秀:你讓...)

嘗試調用是這樣的:

[self.locationManager startUpdatingLocation]; 

而且應該這樣做

0

在iOS系統-8需要做一些改變:

locationManager = [[CLLocationManager alloc] init]; 
    locationManager.delegate = self; 
    locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
    if([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]){ 
     [locationManager requestWhenInUseAuthorization]; 
    }else{ 
     [locationManager startUpdatingLocation]; 
    } 

需要添加2個額外鍵plist出現空白值 1)NSLocationWhenInUseUsageDescription 2)NSLocationAlwaysUsageDescription

#pragma mark - CLLocationManagerDelegate 

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error 
{ 
    NSLog(@"didFailWithError: %@", error); 
    UIAlertView *errorAlert = [[UIAlertView alloc] 
           initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
    [errorAlert show]; 
} 

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
{ 
    NSLog(@"didUpdateToLocation: %@", newLocation); 
    CLLocation *currentLocation = newLocation; 

    if (currentLocation != nil) { 
     NSString *strLat = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude]; 
     NSString *strLong = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude]; 
    } 
} 
相關問題