无法在 uiimageview 中将地图设置为图像 swift

not able to set map as image in uiimageview swift

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])

以上代码无效。

试试这个。请注意,您必须从 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"))

始终在浏览器中检查 link 以查看它是否正常工作意味着图像正确显示而没有任何 Map error: g.co/staticmaperror。如果您发现 staticmaperror,请访问 map-static-error-messages

示例图片:

https://maps.googleapis.com/maps/api/staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=13&size=600x300&maptype=roadmap&key=AIzaSyAJgFSXOEIqBWIZ2vUcngjpX5fBBFmX6t0