以下のコードを使用して、現在の都市と国を取得しようとしてCLLocationManager
います-
#pragma mark - Core Location Delegate Methods
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
CLGeocoder *reverseGeocoder = [[CLGeocoder alloc] init];
[reverseGeocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error)
{
NSLog(@"reverseGeocodeLocation:completionHandler: Completion Handler called!");
if (error){
NSLog(@"Geocode failed with error: %@", error);
return;
}
NSLog(@"Received placemarks: %@", placemarks);
CLPlacemark *myPlacemark = [placemarks objectAtIndex:0];
NSString *countryCode = myPlacemark.ISOcountryCode;
NSString *countryName = myPlacemark.country;
NSString *city1 = myPlacemark.subLocality;
NSString *city2 = myPlacemark.locality;
NSLog(@"My country code: %@, countryName: %@, city1: %@, city2: %@", countryCode, countryName, city1, city2);
}];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
CLLocationDirection th=[newHeading trueHeading];
NSLog(@"True Heading value is=%f",th);
CLLocationDirection magnetic=[newHeading magneticHeading];
NSLog(@"Magnetic Heading value is=%f",magnetic);
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSString *errorType = (error.code == kCLErrorDenied) ? NSLocalizedString(@"access_denied", @"") : NSLocalizedString(@"unknown_error", @"");
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:NSLocalizedString(@"error_getting_location", @"")
message:errorType
delegate:nil
cancelButtonTitle:NSLocalizedString(@"ok", @"")
otherButtonTitles:nil];
[alert show];
}
それは常に-で結果を出します
私の国コード:IN、countryName:インド、city1 :( null)、city2 :( null)
これで何が問題になるのかわかりません。を使用して都市名を取得できないこの問題に直面した人はいますかCLLocationManager