谷歌地图Api图像不显示在UIImageView swift上。

问题描述 投票:0回答:1

我正试图显示谷歌静态地图上 imageView 但它不工作。

码。

 let imageurl = "https://maps.googleapis.com/maps/api/staticmap?center=&maptype=roadmap&path=color:0x000000%7Cweight:10%7Cenc:q`kzDsacsMyEoIaDiGs@sAYa@OIc@W]VqBnBSRS]qE_IgLeT_BwCwFrEjBpDjA|BqAhA{CjCj@bA&markers=color:green%7Clabel:P%7C30.699000010896544,76.69869985431433&markers=color:red%7Clabel:D%7C30.707998,76.703069&key=AIzaSyDdchM7apzEter6yaWfyQG-dF6AORh34MA&size=404x150"
 let url = URL(string: imageurl)
 let data = try? Data(contentsOf: url!) // Crash
 imageView.image = UIImage(data: data!) 

and { symbols. I just replaced those with their ASCII encoding based on

let imageurl = "https://maps.googleapis.com/maps/api/staticmap?center=&maptype=roadmap&path=color:0x000000%7Cweight:10%7Cenc:q`kzDsacsMyEoIaDiGs@sAYa@OIc@W]VqBnBSRS]qE_IgLeT_BwCwFrEjBpDjA|BqAhA{CjCj@bA&markers=color:green%7Clabel:P%7C30.699000010896544,76.69869985431433&markers=color:red%7Clabel:D%7C30.707998,76.703069&key=AIzaSyDdchM7apzEter6yaWfyQG-dF6AORh34MA&size=404x150"
let newString = imageurl.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!

this chart

from W3.

URLl在chrome或safari中工作得很好,但在代码中却无法工作。

任何帮助将是非常感激的。
ios swift api url google-maps-api-3
1个回答
0
投票

https://maps.googleapis.com/maps/api/staticmap?center=&maptype=roadmap&path=color:0x000000%7Cweight:10%7Cenc:q%60kzDsacsMyEoIaDiGs@sAYa@OIc@W]VqBnBSRS]qE_IgLeT_BwCwFrEjBpDjA%7CBqAhA%7BCjCj@bA&markers=color:green%7Clabel:P%7C30.699000010896544,76.69869985431433&markers=color:red%7Clabel:D%7C30.707998,76.703069&key=AIzaSyDdchM7apzEter6yaWfyQG-dF6AORh34MA&size=404x150

我试图在imageView上显示google静态地图,但它不工作。代码:让imageurl = "https:/maps.googleapis.commapsapistaticmap?center=&maptype=roadmap&path=color:..."。把你的URL字符串改成这样。问题出在`

© www.soinside.com 2019 - 2024. All rights reserved.