Json 谷歌地图API搜索请求无英语位置(SWIFT)
当我尝试在浏览器上获取店铺坐标时,我使用以下链接获得json结果,没有任何错误:Json 谷歌地图API搜索请求无英语位置(SWIFT),json,swift,xcode,google-maps,swift4,Json,Swift,Xcode,Google Maps,Swift4,当我尝试在浏览器上获取店铺坐标时,我使用以下链接获得json结果,没有任何错误: ”https://maps.googleapis.com/maps/api/place/radarsearch/json?location=24.712587,46.673184&radius=5000&name= 但是当我在Xcode中通过Alamofire进行HTTP请求时 let url = "https://maps.googleapis.com/maps/api/place/radarsearch/jso
”https://maps.googleapis.com/maps/api/place/radarsearch/json?location=24.712587,46.673184&radius=5000&name=
但是当我在Xcode中通过Alamofire进行HTTP请求时
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搜索英文名称时,它就起作用了 我的猜测是,苹果的框架被拉丁和阿拉伯字符的混合绊倒了。您可以通过分离两个组件来解决此问题:
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
...
}
我的猜测是,苹果的框架被拉丁和阿拉伯字符的混合绊倒了。您可以通过分离两个组件来解决此问题:
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
谢谢你的回答。我刚想出来。我必须对名称进行编码encodeURI