Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS geocodeAddressString为postalCode返回空值_Ios_Geocoding - Fatal编程技术网

iOS geocodeAddressString为postalCode返回空值

iOS geocodeAddressString为postalCode返回空值,ios,geocoding,Ios,Geocoding,我正在用城市名称(例如西雅图、洛杉矶等)调用geocodeAddressString。在Xcode模拟器中,这将返回一个正确的placemark值,但不返回postalCode: [geocoder geocodeAddressString:placename completionHandler:^(NSArray *placemarks, NSError *error) { //Error checking NSLog(@"placemarks %i",[placemarks

我正在用城市名称(例如西雅图、洛杉矶等)调用geocodeAddressString。在Xcode模拟器中,这将返回一个正确的placemark值,但不返回postalCode:

[geocoder geocodeAddressString:placename completionHandler:^(NSArray *placemarks, NSError *error) {
    //Error checking
    NSLog(@"placemarks %i",[placemarks count]);

    if ([placemarks count] == 1) { // one city returned. set location accordingly
        CLPlacemark *placemark = [placemarks objectAtIndex:0];
        NSLog(@"one location found %@",placemark);
        [self setUserLocation:placemark];
    } 

}];
输出placemark值:

- (void)setUserLocation:(CLPlacemark *)placemark {
  NSLog(@"found zip %@",placemark.postalCode);
  NSLog(@"found city %@",placemark.locality);
  NSLog(@"found state %@",placemark.administrativeArea);
  NSLog(@"found country %@",placemark.ISOcountryCode);
  NSLog(@"found lat %f",placemark.region.center.latitude);
  NSLog(@"found long %f",placemark.region.center.longitude);
}
显示以下内容:

2014-05-21 07:28:12.378 jobagent[5157:60b] entered location seattle
2014-05-21 07:28:12.378 jobagent[5157:60b] placename seattle
2014-05-21 07:28:12.992 jobagent[5157:60b] placemarks 1
2014-05-21 07:28:12.993 jobagent[5157:60b] one location found Seattle, WA, United States @   <+47.60620950,-122.33207080> +/- 100.00m, region CLCircularRegion (identifier:'<+47.56346943,-122.32853603> radius 26395.84', center:<+47.56346943,-122.32853603>, radius:26395.84m)
2014-05-21 07:28:12.993 jobagent[5157:60b] found zip (null)
2014-05-21 07:28:12.994 jobagent[5157:60b] found city Seattle
2014-05-21 07:28:12.994 jobagent[5157:60b] found state WA
2014-05-21 07:28:12.995 jobagent[5157:60b] found country US
2014-05-21 07:28:12.995 jobagent[5157:60b] found lat 47.563469
2014-05-21 07:28:12.996 jobagent[5157:60b] found long -122.328536
2014-05-21 07:28:12.378工作人员[5157:60b]进入西雅图
2014-05-21 07:28:12.378求职者[5157:60b]地名西雅图
2014-05-21 07:28:12.992职业介绍所[5157:60b]地名1
2014-05-21 07:28:12.993 jobagent[5157:60b]在美国西澳州西雅图的一个地点,距离为+/-100.00m,区域为CLCircularRegion(标识符:“半径26395.84”,中心:,半径26395.84m)
2014-05-21 07:28:12.993工作代理[5157:60b]找到zip(空)
2014-05-21 07:28:12.994求职者发现西雅图市
2014-05-21 07:28:12.994职业介绍所[5157:60b]发现华盛顿州
2014-05-21 07:28:12.995职业介绍所[5157:60b]在美国发现
2014-05-21 07:28:12.995职业介绍所[5157:60b]发现lat 47.563469
2014-05-21 07:28:12.996找到的职业中介[5157:60b]长-122.328536

CLGeocoder
不会仅返回一个城市的
postalCode
,因为存在多个
postalCode


要获取
postalCode
,您需要更加具体,例如写街道

,这是有意义的,但是有一个
CLLocation
返回了特定的经度和纬度。为什么它不返回与此相关的邮政编码?这在很多情况下都很有用。谢谢。现在有道理了。因此,我添加了以下内容以获取placemark的邮政编码:CLLocation loc=[[CLLocation alloc]initWithLatitude:placemark.region.center.latitude经度:placemark.region.center.longitude];[geocoder ReverseGeoLocation:loc completionHandler:^(NSArray placemarks,NSError*错误){if([placemarks count]>0){[self-setUserLocation:[placemarks objectAtIndex:0]];}}};我这样做了,但仍然没有找到postalCode。我记录了completionHandler返回的整个placemarker,并搜索键postalCode和zipCode,但没有找到一个实体。