我收到addressString后调用此函数:
[[self geocoder] geocodeAddressString:addressString completionHandler:^(NSArray *placemarks, NSError *error) {
if (error) {
block(nil, nil, error);
} else {
CLPlacemark *placemark = [placemarks onlyObject];
block(placemark, self.name, error);
}
}];
它将地标返回为nil,错误为: 错误域= kCLErrorDomain代码= 8“无法完成操作。(kCLErrorDomain错误8。)”
我的地址字符串是从这个字典中检索到placeDictionary [@“formatted_address”]:
placeDictionary =
{
"address_components" = (
{
"long_name" = "Palolem Beach";
"short_name" = "Palolem Beach";
types = (
"natural_feature",
establishment
);
},
{
"long_name" = "South Goa";
"short_name" = "South Goa";
types = (
"administrative_area_level_2",
political
);
},
{
"long_name" = Goa;
"short_name" = GA;
types = (
"administrative_area_level_1",
political
);
},
{
"long_name" = India;
"short_name" = IN;
types = (
country,
political
);
}
);
"adr_address" = "Palolem Beach, <span class=\"region\">Goa</span>";
"formatted_address" = "Palolem Beach, Goa";
geometry = {
location = {
lat = "15.0099648";
lng = "74.02321859999999";
};
viewport = {
northeast = {
lat = "15.012671";
lng = "74.0272093";
};
southwest = {
lat = "15.0050025";
lng = "74.0164053";
};
};
};
icon = "http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png";
id = b286a0f7f047e162b3cab2ab3328ce95d26bdb52;
name = "Palolem Beach";
reference = "CnRwAAAAh2ZORbEpxNv5HnZlQRY_VxKLdvAd16OusSwtBlAKibDFP6roT2idnPvm-XRgMlw3iqUsZujVFrOOns76fK9we3Uddt4b3GgcWZoSqSgoYGtbHh1l5PEL_0VAwaUcswomroA3sjd3dN8lXyBSvafrrxIQONHTpwpn6IvGtYZ12pZ5ixoUENbjRTo3dCrN3aoZTM0k5EPXAjA";
types = (
"natural_feature",
establishment
);
url = "https://maps.google.com/maps/place?q=Palolem+Beach&ftid=0x3bbe4551d05b02bb:0x1e1bc67d4b0fbbf5";
}
即使我使用方法:
[[self geocoder] geocodeAddressDictionary:placeDictionary completionHandler:^(NSArray *placemarks, NSError *error){
}];
它给我带来了同样的错误。
答案 0 :(得分:16)
如果Apple的Geocoder对提供的地址一无所知,您会收到此错误。
根据Apple documentation代码8表示kCLErrorGeocodeFoundNoResult
答案 1 :(得分:6)
我认为它给你错误,因为地理编码器无法找到位置。
检查此代码,我已对其进行了修改
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:@"Palolem Beach, Goa, India" completionHandler:^(NSArray* placemarks, NSError* error){
if (!error) {
for (CLPlacemark* aPlacemark in placemarks)
{
NSLog(@"place--%@", [aPlacemark locality]);
NSLog(@"lat--%f\nlong--%f",aPlacemark.location.coordinate.latitude,aPlacemark.location.coordinate.longitude);
}
}
else{
NSLog(@"error--%@",[error localizedDescription]);
}
}];
答案 2 :(得分:1)
我最近发现,使用美国邮政编码时,例如01844对马萨诸塞州来说,如果我放弃0并通过1844年,那么如果您拥有进行中的0,它将无法正常工作。