gpt4 book ai didi

ios - 无法弄清楚如何将字符串编码为 Google Static Map API iOS 的 URL

转载 作者:行者123 更新时间:2023-11-28 08:04:43 25 4
gpt4 key购买 nike

我现在真的很绝望。我已经连续 7 个小时进行编码和调试,从弄清楚如何在 Google 静态 map 中绘制一个圆圈,到将代码从 PHP 和 Java 转换为 Swift,只是为了看看解决方案是否可行。

幸运的是,我足够幸运,能够正确生成带有 Circle 的 Google 静态 map 。但是,我现在的问题是如何将它(字符串 URL)正确编码为 URL。我已经尝试了几乎所有我在 SO 上找到的东西。

这是我的日志中浏览器中的示例工作 URL:

WORKING GOOGLE STATIC MAP LINK

https://maps.googleapis.com/maps/api/staticmap?size=640x320&&path=color:0x2EB7FCDD%7Cweight:1%7Cfillcolor:0x2EB7FC80%7Cenc:umdxAip_bVFqARmA^iAl@aAt@w@`Ao@dAa@jASlAGlAFjARdA`@`An@t@v@l@`A^hARlAFpAGnASlA_@hAm@`Au@x@aAl@eA`@kARmAFmAGkASeAa@aAm@u@y@m@aA_@iASmA&key=AIzaSyDLDkhgnS5gUjlXl5Jqt8fxJq87Figz8co&zoom=15

我已经尝试了每个 CharacterSet 来将该字符串编码为 URL。

一些结果是:

GPKit🐞🐞🐞 -- JobLocationTableViewCell 2017-08-04 19:55:53 +0000: -- HOST --> https%3A%2F%2Fmaps.googleapis.com%2Fmaps%2Fapi%2Fstaticmap%3Fsize=640x320&&path=color%3A0x2EB7FCDD%257Cweight%3A1%257Cfi ... &zoom=15
GPKit🐞🐞🐞 -- JobLocationTableViewCell 2017-08-04 19:55:53 +0000: -- QUERY --> https://maps.googleapis.com/maps/api/staticmap?size=640x320&&path=color:0x2EB7FCDD%257Cweight:1%257Cfillcolor:0x2EB7FC80%257Cenc:umdxAip_bVFqARmA%5EiAl@aAt@w@%60Ao@dAa@jASlAGlAFjARdA%60@%60An@t@v@l@%60A%5EhARlAFpAGnASlA_@hAm@%60Au@x@aAl@eA%60@kARmAFmAGkASeAa@aAm@u@y@m@aA_@iASmA&key=AIzaSyDLDkhgnS5gUjlXl5Jqt8fxJq87Figz8co&zoom=15
GPKit🐞🐞🐞 -- JobLocationTableViewCell 2017-08-04 19:55:53 +0000: -- WHITE SPACES --> %68%74%74%70%73%3A%2F%2F%6D%61%70%73%2E%67%6F%6F%67%6C%65%61%70%69%73%2E%63%6F%6D%2F%6D%61%70%73%2F%61%70%69%2F%73%74%61 ... 3D%31%35
GPKit🐞🐞🐞 -- JobLocationTableViewCell 2017-08-04 19:55:53 +0000: -- nonBaseCharacters --> %68%74%74%70%73%3A%2F%2F%6D%61%70%73%2E%67%6F%6F%67%6C%65%61%70%69%73%2E%63%6F%6D%2F%6D%61%70%73%2F%61%70%69%2F%73%74%61 ... 3D%31%35
GPKit🐞🐞🐞 -- JobLocationTableViewCell 2017-08-04 19:55:53 +0000: -- alphanumerics --> https%3A%2F%2Fmaps%2Egoogleapis%2Ecom%2Fmaps%2Fapi%2Fstaticmap%3Fsize%3D640x320%26%26path%3Dcolor%3A0x2EB7FCDD%257Cweigh ... oom%3D15
GPKit🐞🐞🐞 -- JobLocationTableViewCell 2017-08-04 19:55:53 +0000: -- urlFragmentAllowed --> https://maps.googleapis.com/maps/api/staticmap?size=640x320&&path=color:0x2EB7FCDD%257Cweight:1%257Cfillcolor:0x2EB7FC80%257Cenc:umdxAip_bVFqARmA%5EiAl@aAt@w@%60Ao@dAa@jASlAGlAFjARdA%60@%60An@t@v@l@%60A%5EhARlAFpAGnASlA_@hAm@%60Au@x@aAl@eA%60@kARmAFmAGkASeAa@aAm@u@y@m@aA_@iASmA&key=AIzaSyDLDkhgnS5gUjlXl5Jqt8fxJq87Figz8co&zoom=15
GPKit🐞🐞🐞 -- JobLocationTableViewCell 2017-08-04 19:55:53 +0000: -- decomposables --> %68%74%74%70%73%3A%2F%2F%6D%61%70%73%2E%67%6F%6F%67%6C%65%61%70%69%73%2E%63%6F%6D%2F%6D%61%70%73%2F%61%70%69%2F%73%74%61 ... 3D%31%35

这些在我的浏览器或我的图像下载器功能中都不起作用。欢迎回答 Swift 或 Objective-C。

编辑:当然,我使用 URL 下载生成的静态 map 图像,就像这样(我使用的是一个名为 Kingfisher 的库)

let mapURL = URL(string: staticMapUrl.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!)
self.imageView_Map.kf.setImage(
with: mapURL,
placeholder: nil,
options: [.transition(.fade(1))],
progressBlock: { (receivedSize, totalSize) in
}, completionHandler: { (_, _, _, _) in })

最佳答案

Kingfisher 文档说:

  let url = URL(string: "url_of_your_image")
imageView.kf.setImage(with: url)

所以,你需要做的就是

  let url = URL(string: "https://maps.googleapis.com/maps/api/staticmap?size=640x320&&path=color:0x2EB7FCDD%7Cweight:1%7Cfillcolor:0x2EB7FC80%7Cenc:umdxAip_bVFqARmA%5EiAl@aAt@w@%60Ao@dAa@jASlAGlAFjARdA%60@%60An@t@v@l@%60A%5EhARlAFpAGnASlA_@hAm@%60Au@x@aAl@eA%60@kARmAFmAGkASeAa@aAm@u@y@m@aA_@iASmA&key=AIzaSyDLDkhgnS5gUjlXl5Jqt8fxJq87Figz8co&zoom=15")
imageView.kf.setImage(with: url)

我没有看到您需要编码的内容。

关于ios - 无法弄清楚如何将字符串编码为 Google Static Map API iOS 的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45514671/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com