Swift3 通过nearbysearch Google web服务使用多个类型时获取无效url

Swift3 通过nearbysearch Google web服务使用多个类型时获取无效url,swift3,Swift3,当我尝试使用多个类型(如在查询中)实现时,获取URL无效 百货商店、杂货店或超市 let query = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=28.965198333333333,77.98569833333333&radius=3218&type=department_store|grocery_or_supermarket&key=API_KEY" guard

当我尝试使用多个类型(如在查询中)实现时,获取URL无效 百货商店、杂货店或超市

let query = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=28.965198333333333,77.98569833333333&radius=3218&type=department_store|grocery_or_supermarket&key=API_KEY"

guard let url = URL(string: query) else { return completion(.Failure("URL invalid")) }
虽然它可以很好地与单一类型

let query = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=28.965198333333333,77.98569833333333&radius=3218&type=grocery_or_supermarket&key=API_KEY"
请建议,我如何在nearbysearchweb服务中使用多种类型


提前感谢。

通过使用解决。guard let escapedQuery=query.addingPercentEncoding(使用AllowedCharacters:CharacterSet.UrlQueryLowed),let url=url(字符串:escapedQuery),否则{返回完成(.Failure(“url无效”)}将通过使用解决。guard let escapedQuery=query.addingPercentEncoding(带AllowedCharacters:CharacterSet.UrlQueryLowed),let url=url(字符串:escapedQuery)else{返回完成(.Failure(“url无效”)}