谷歌地图API搜索请求没有英语的地方(SWIFT)
问题描述:
当我试图让店里的坐标上的浏览器我得到通过此链接JSON结果没有错误:谷歌地图API搜索请求没有英语的地方(SWIFT)
"https://maps.googleapis.com/maps/api/place/radarsearch/json?location=24.712587,46.673184&radius=5000&name=ستاربكس&key=#####"
但是当我做HTTP请求通过Alamofire在Xcode
let url = "https://maps.googleapis.com/maps/api/place/radarsearch/json?location=24.712587,46.673184&radius=5000&name=ستاربكس&key=####"
let requestURL =
Alamofire.request(url).responseJSON
{ response in
print(response.result.debugDescription)
print(response.request) // original URL request
print(response.response)
print(response.data) // server data
print(response.result) // result of response serialization
if let JSON = response.result.value {
print("JSON: \(JSON)")
}
}
}
我得到所有打印的零!它为什么这样做?但是,当我通过Alamofire要求搜索英文名称时,它可以工作!
答
我的猜测是Apple的框架中拉丁语和阿拉伯字符的混合物。您可以通过分开两个组件来解决它:
var urlComponents = URLComponents(string: "https://maps.googleapis.com/maps/api/place/radarsearch/json?location=24.712587,46.673184&radius=5000&key=xxx")!
urlComponents.queryItems?.append(URLQueryItem(name: "name", value: "ستاربكس"))
let requestURL =
Alamofire.request(urlComponents).responseJSON { response in
...
}
谢谢您的回答。我只是想出了它。我不得不编码名称“encodeURI” – leo0019