简体   繁体   English

CLLocation数据在iOS中为空

[英]CLLocation data getting null in iOS

Hello I am getting user location using CLLocationManager I can get latitude,longitude,country name and administrative area. 您好,我正在使用CLLocationManager获取用户位置,我可以获取纬度,经度,国家/地区名称和管理区域。 But I want to get the city name or sub administrative area. 但是我想获得城市名称或子行政区域。

NSString *address = [NSString stringWithFormat:@"%@ %@\n%@ %@\n%@\n%@",
                             self.placemark.subThoroughfare, self.placemark.thoroughfare,
                             self.placemark.postalCode, self.placemark.subLocality,
                             self.placemark.subAdministrativeArea,
                            self. placemark.country];

but except the country andthoroughfare other values are null. 但除了国家和通行费外,其他值均为null。 Why is that? 这是为什么? How can I solve this issue? 我该如何解决这个问题? Please help me. 请帮我。 Thanks 谢谢

you have to get country value and address string from addressDictionary Like 您必须从addressDictionary获得国家/地区值和地址字符串,例如

NSDictionary *dictAddress = [NSDictionary dictionaryWithDictionary:placemark.addressDictionary];
    NSMutableDictionary *dictTxtData = [NSMutableDictionary dictionary];
    NSLog(@"country:%@",dictAddress[@"Country"]);

you have to get other details from placemark 您必须从placemark获取其他详细信息

NSLog(@"thoroughfare:%@",placemark.thoroughfare);
    NSLog(@"subThoroughfare:%@",placemark.subThoroughfare);
    NSLog(@"subAdministrativeArea:%@",placemark.subAdministrativeArea);
    NSLog(@"postCode:%@",placemark.postalCode);

if you have get nil value then change location or check with popular location and check it again and use direct placemark insten of self.placemark . 如果你有获得零值,则改变位置或与流行的位置检查并再次检查并使用直接placemark中insten self.placemark my output is: 我的输出是:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM