URL不接受使用或(|)参数Swift 3的查询字符串



我正在尝试实现近亲搜索Google Web服务,例如在QUERY type> type = demptsent_store中| grocery_or_supermarket

所以,我已经准备了一个查询字符串,如下所述,该字符串在浏览器上正常工作

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"

当我尝试将其转换为URL时,如下所述,它给了我错误" URL无效" ,因为URL不使用或(|)参数接受查询字符串

guard let url = URL(string: query) else { return completion(.Failure("URL invalid")) }

在与单一类型的工作正常时 type = depentment_store

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"

请建议,我如何使用近亲搜索Web服务多种类型。

预先感谢。

添加百分比编码:

guard let escapedQuery = query.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed),
      let url = URL(string: escapedQuery) else { return completion(.Failure("URL invalid")) }

最新更新