2017-11-11 66 views
1

當我試圖讓店裏的座標上的瀏覽器我得到通過此鏈接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要求搜索英文名稱時,它可以工作!

回答

0

我的猜測是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 
     ... 
    } 
+0

謝謝您的回答。我只是想出了它。我不得不編碼名稱「encodeURI」 – leo0019