我正在使用Yelp API,这是搜索方法:
func searchWithTerm(term: String, success: (AFHTTPRequestOperation!, AnyObject!) -> Void, failure: (AFHTTPRequestOperation!, NSError!) -> Void) -> AFHTTPRequestOperation! {
// For additional parameters, see http://www.yelp.com/developers/documentation/v2/search_api
var parameters = ["term": term, "ll": "37.77493,-122.419415"]
return self.GET("search", parameters: parameters, success: success, failure: failure)
}
目前使用给定的ll参数进行硬编码。我有一个用户的位置存储在一个不同的VC中,当我尝试传入lat和long来替换硬编码值时,我得到错误...
我将位置存储在主ViewController中作为CLLocationCoordinate2D。我想更改searchWithTermMethod
中的坐标我做错了什么?传递double的值应该相当简单......
我尝试这样做:
func searchWithTerm(term: String, success: (AFHTTPRequestOperation!, AnyObject!) -> Void, failure: (AFHTTPRequestOperation!, NSError!) -> Void) -> AFHTTPRequestOperation! {
// For additional parameters, see http://www.yelp.com/developers/documentation/v2/search_api
var parameters = ["term": term, "ll": userLocation.latitude, userLocation.longitude]
return self.GET("search", parameters: parameters, success: success, failure: failure)
}
和错误:“预期':'在字典文字中”
答案 0 :(得分:1)
您需要将纬度和经度组合成一个字符串,您可以使用插值来执行此操作:
var parameters = ["term": term, "ll": "\(userLocation.latitude), \(userLocation.longitude)"]