<分区>
我在开发我的 iOS 应用程序时遇到了一个问题,我想要实现的是从一个字符串数组创建一个字符串。该数组包含给定位置的地址,使用 CLGeocoder
从反向地理编码中获得,这是给我字符串数组的代码:
let userCoordinates = CLLocation(latitude: mapView.userLocation.location!.coordinate.latitude, longitude: mapView.userLocation.location!.coordinate.longitude)
CLGeocoder().reverseGeocodeLocation(userCoordinates, completionHandler: {
placemark, error in
let reverseGeocodedLocation = placemark?.first?.addressDictionary?["FormattedAddressLines"] as? [String]
}
reverseGeocodedLocation
在我的例子中是:
["Apple Inc.", "Cupertino, CA 95014", "United States"]
结果字符串应将数组中的字符串分开,并以多行格式呈现,如下所示:
Apple Inc.
Cupertino, CA 95014
United States
我已经尝试在网上搜索解决方案,我发现这段代码应该可以做到这一点,这可能是解决方案:
print("\n".join(reverseGeocodedLocation.map({$0})))
但是编译器说:
Cannot invoke 'join' with an argument list of type '([String]?)'