gpt4 book ai didi

ios - 谷歌地图 API : String URL Enconding

转载 作者:可可西里 更新时间:2023-11-01 00:50:53 24 4
gpt4 key购买 nike

我正在使用以下代码搜索地点:

let correctedAddress:String! = self.searchResults[(indexPath as NSIndexPath).row].addingPercentEncoding(withAllowedCharacters: CharacterSet.symbols)

let url = URL(string: "https://maps.googleapis.com/maps/api/geocode/json?address=\(correctedAddress)&sensor=false")

self.searchResults[(indexPath as NSIndexPath).row] 返回如下字符串:“São Paulo - State of São Paulo, Brazil”

URL的参数字符串是这样的(编码后):

https://maps.googleapis.com/maps/api/geocode/json?address=Optional(\%22State%20of%20S%C3%A3o%20Paulo%2C%20Brazil\%22)&sensor=false

如果我在网络浏览器中搜索此 URL,则会显示 JSON。所以我假设它是一个有效的 URL,但是 URL(string: ..) 方法总是返回 nil

我可能需要更改我的编码,我尝试使用 CharacterSet.urlPathAllowed 但总是返回 nil。

我应该使用哪种编码?或者还有其他问题?

最佳答案

尝试删除 url 中的 Optional(...) 字符串

https://maps.googleapis.com/maps/api/geocode/json?address=\%22State%20of%20S%C3%A3o%20Paulo%2C%20Brazil\%22&sensor=false

我相信这就是 URL 返回 nil 的原因。

关于ios - 谷歌地图 API : String URL Enconding,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39562299/

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