使用当前位置数据时,CLGeocoder返回城市和州的空结果
嗨,我想获得使用CLGeocoder城市和国家的名称。 但是,placemark.addressDictionary正在返回我:
{FormattedAddressLines =(“南大西洋”); 名称=“南大西洋”; 海洋=“南大西洋”; }
并且地标是:南大西洋,南大西洋@ <-42.60533670,-21.93128480> +/- 100.00m,区域CLCircularRegion(标识符:“< – 41.51023865,-31.60774370>半径4958095.65',中心:< – 41.51023865,-31.60774370 >,半径:4958095.65米)
此外,[地标地点]和[地标pipe理区域]的NSLog都显示为零。
还尝试添加ABAdressBookUI,ABAdressBook框架并获取数据为:
NSString * addressDict = ABCreateStringWithAddressDictionary(placemark.addressDictionary,NO); 它返回一个空描述的对象。
或者试过:NSString * state =(NSString *)[placemark.addressDictionary objectForKey:kABPersonAddressStateKey]; 它会抛出不兼容指针types的警告。
如果有任何可能的解决scheme或如果我失去了一些东西,请让我知道。
当前位置button被点击时,我的代码如下:
CLLocation * loc;
loc = [[CLLocation alloc] initWithLatitude:[KLocationManager sharedManager]._locationManager.location.coordinate.latitude longitude:[KLocationManager sharedManager]._locationManager.location.coordinate.longitude]; CLGeocoder* geocoder = [[CLGeocoder alloc] init]; [geocoder reverseGeocodeLocation:loc completionHandler:^(NSArray *placemarks, NSError *error) { CLPlacemark* placemark = [placemarks objectAtIndex:0]; if (placemark) { NSDictionary* dic = placemark.addressDictionary; NSString* locName = [NSString stringWithFormat:@"%@, %@", [dic objectForKey:@"City"],[dic objectForKey:@"State"]]; CLLocation* loc = placemark.location; self.returnLocationDict = @{@"name":locName, @"location":loc}; } }];
我在这里错过了什么?
复制所遇到的一种方法是使用经度和纬度为0,0的CLLocation
我用纬度:37.3318经度:-122.0312(无限循环..)运行你的代码,并按预期工作。
您的位置经理可能不会返回您所期望的。