如何在swift中将kml文件中的图标添加到mapkit

如何在swift中将kml文件中的图标添加到mapkit,swift,mapkit,kml,Swift,Mapkit,Kml,我有一个kml文件: 在地图套件上显示kml文件中的所有数据后,一切正常。但在kml文件中,我无法显示图标 这是kml文件中的图标: 这是一个注释代码: open class KMLDocument: KMLElement { open var overlays: [MKOverlay] = [] open var annotations: [KMLAnnotation] = [] open var styles: [String: KMLStyle] = [:

我有一个kml文件:

在地图套件上显示kml文件中的所有数据后,一切正常。但在kml文件中,我无法显示图标

这是kml文件中的图标:

这是一个注释代码:

open class KMLDocument: KMLElement {
     open var overlays: [MKOverlay] = []
     open var annotations: [KMLAnnotation] = []
     open var styles: [String: KMLStyle] = [:]
     open var placemarks: [KMLPlacemark] = []

     public convenience init(_ element: AEXMLElement, generateMapKitClasses: Bool) {
        self.init(element)
        if generateMapKitClasses {
            initOverlay()
            initAnnotation()
        }
    }

    fileprivate func initAnnotation() {
        for pointPlacemark: KMLPlacemark in placemarks {
            if let point: KMLPoint = pointPlacemark.point {
                let annotation = KMLAnnotation(point.coordinates)
                annotation.title = pointPlacemark.name
                annotation.subtitle = pointPlacemark.description
                annotation.style = pointPlacemark.style
                self.annotations.append(annotation)
            }
        }
    }
}

为了使KML文件中的图标图像在Google Earth或Maps中正确显示,图标图像需要公开访问。当我将你的图标图像的URL放入我的浏览器()时,我只得到一个黑屏,没有图像。因此,无论出于何种原因,该URL都不会返回有效的、可公开访问的图像文件。它可能在KML查看器中正常工作,该查看器具有对该服务器的特殊访问权限并可以获取图像,但在其他任何地方可能都不起作用。您可能还希望检查它是否实际返回PNG文件,而不是SVG文件(因为URL在两个位置包含“SVG”),因为KML只支持JPG、PNG和GIF图像(加上TIFF和GeoTiff用于覆盖)