gpt4 book ai didi

ios - 如何传入纬度和经度参数 Yelp API

转载 作者:行者123 更新时间:2023-11-29 01:47:16 28 4
gpt4 key购买 nike

我正在使用 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 中,当我尝试传递经纬度来替换硬编码值时,我收到错误...

我将位置存储在主 ViewController 中作为 CLLocationCooperative2D。然后我想更改 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)
}

和错误:“字典文字中预期有 ':'”

最佳答案

您需要将纬度和经度组合成一个字符串,您可以使用插值来实现:

var parameters = ["term": term, "ll": "\(userLocation.latitude), \(userLocation.longitude)"]

关于ios - 如何传入纬度和经度参数 Yelp API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31757640/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com