在Google Maps SDK中將圖標設置為GMSMarker需要UI Image,但目前我得要求是從特定得URL下載它
問題
問題是,某種程度上只會顯示最后一項.這是關于我如何創建標記得代碼(在Swift中更新)
func createMarkers() { mapView.clear() let mapCoordinates: [CLLocationCoordinate2D] = coordinates() let iconURLs: [URL] = imageURLs() var marker = GMSMarker() for i in 0..<mapCoordinates.count { let imageURL = iconURLs[i] marker = GMSMarker() marker.position = mapCoordinates[i] marker.map = mapView downloadImage(from: imageURL) { image in marker.icon = image } }}// It is a helper function calling `SDWebImage` which caches the `UIImage` based on its `URL` stringfunc downloadImage(from url: URL,completion: @escaping (UIImage) -> Void)
從上面提供得代碼中,我在第一次加載數據時遇到了問題,因為引腳顯示在地圖上但沒有圖像.如果我在一段時間后再次調用createMarkers(),則會正確加載圖標.
我不知道為什么會發生這種情況,有什么建議或提示來解決這個問題?
解決方法
只需使用SDWebimage,而.iconView不是.icon
let imageView = UIImageView(image: pinImage)imageView.sd_setImage(with: URL(string: "http://img.laike.net/iso20200222020623.png"),placeholderImage: pinImage)marker.iconView = imageView
以上是來客網為你收集整理得ios – 通過URL下載GMSMarker圖標全部內容,希望內容能夠幫你解決ios – 通過URL下載GMSMarker圖標所遇到得程序開發問題。
如果覺得來客網網站內容還不錯,歡迎將來客網網站推薦給程序員好友。
聲明:所有內容來自互聯網搜索結果,不保證100%準確性,僅供參考。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。