//創(chuàng)建地理編碼對(duì)象? ? CLGeocoder *geocoder=[[CLGeocoder alloc]init];? ? //創(chuàng)建位置? ? CLLocation *location=[[CLLocation alloc]initWithLatitude:userLocation.location.coordinate.latitude longitude:userLocation.location.coordinate.longitude];? ? ? ? //反地理編碼? ? [geocoder reverseGeocodeLocation:location completionHandler:^(NSArray* _Nullable placemarks, NSError * _Nullable error) {
//判斷是否有錯(cuò)誤或者placemarks是否為空
if (error !=nil || placemarks.count==0) {
NSLog(@"%@",error);
return ;
}
for (CLPlacemark *placemark in placemarks) {
//賦值詳細(xì)地址
annotoation.title = [NSString stringWithFormat:@"%@%@",placemark.administrativeArea,placemark.locality];
annotoation.subtitle? =[NSString stringWithFormat:@"%@%@",placemark.subLocality,placemark.name];
}
}];