【问题标题】:CLLocation data getting null in iOSCLLocation 数据在 iOS 中为空
【发布时间】:2016-06-20 13:16:50
【问题描述】:

您好,我正在使用CLLocationManager获取用户位置,我可以获取纬度、经度、国家名称和行政区域。但我想获取城市名称或子行政区域。

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];

但除了国家和地区之外,其他值为空。这是为什么?我该如何解决这个问题?请帮我。 谢谢

【问题讨论】:

  • 从addressdictionary获取国家和地址信息

标签: ios objective-c cllocationmanager clgeocoder


【解决方案1】:

您必须从addressDictionary Like 获取国家值和地址字符串

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

您必须从placemark获取其他详细信息

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

如果您得到 nil 值,则更改位置或检查热门位置并再次检查并直接使用 placemark insten 或 self.placemark。 我的输出是:

【讨论】:

  • 但是这个只有国家代码,国家,州和街道,我怎样才能得到城市名称或子行政区域?
  • @user1960169 请检查我更新的 ans 。就我而言,我使用了没有自我的地标,请检查设置的热门位置。多次位置管理器无法正确获取位置。
猜你喜欢
  • 2016-11-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-08
  • 2012-06-06
  • 1970-01-01
  • 2011-07-12
  • 2012-03-21
相关资源
最近更新 更多