let staticURL : String = "https://www.google.com/maps/place/London,+UK/@51.528308,-0.3817765,10z/data=!3m1!4b1!4m5!3m4!1s0x47d8a00baf21de75:0x52963a5addd52a99!8m2!3d51.5073509!4d-0.1277583\("zoom=15&size=\(2 * Int(imgForMap.frame.size.width))x\(2 * Int(imgForMap.frame.size.height))")&sensor=true"
let mapURL = URL(string: staticURL)!
self.imgForMap.sd_setAnimationImages(with: [mapURL as URL])
以上代码不起作用。
答案 0 :(得分:2)
尝试一下。请注意,您必须从Google cloud
获取API密钥let API_Key = //Your API Key.
let url = "https://maps.googleapis.com/maps/api/staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=13&size=\(2 * Int(imgBanner.frame.size.width))x\(2 * Int(imgBanner.frame.size.height))&maptype=roadmap&key=\(API_Key)"
let mapUrl: NSURL = NSURL(string: staticMapUrl)!
self.imgBanner.sd_setImage(with: mapUrl as URL, placeholderImage: UIImage(named: "palceholder"))
始终检查浏览器中的链接以查看其是否工作正常,这表示图像中是否可见。
示例图片: