我正在尝试完成对Dark sky API的.get请求,该请求需要以下参数来完成请求:https://api.darksky.net/forecast/[key]/[latitude],[longitude]
我的代码如下所示,我在“方法”调用中得到一个“额外参数”,我认为这是因为我的函数数据类型错误。我一直在尝试寻找合适的,但是我做对了。
我的Alamofire请求如下:
{
"shell_cmd": "echo \\$HOME/",
}
和我的“更新方法”如下,使用手机gps获取所需的用户纬度和经度:
//Get wind data method
func getWindData(url: String, key: Any, latitude: Any, longitude: Any) {
Alamofire.request(url, method: .get, key, latitude, longitude).responseJSON {
response in
if response.result.isSuccess {
print("Success! Got the weather data")
let windJSON : JSON = JSON(response.result.value!)
print(windJSON)
}
else {
print("Error \(String(describing: response.result.error))") }
self.yard.text = "Connection issues"
}
}
非常感谢!亚历克斯
答案 0 :(得分:0)
您需要
let openWeatherMapBaseURL = "https://api.darksky.net/forecast/Key_Here/"
let urlStr = "\(openWeatherMapBaseURL)\(latitude),\(longitude)"
Alamofire.request(urlStr, method: .get, parameters:nil, encoding: JSONEncoding.default).responseJSON { [weak self] response in
}
不存在
Alamofire.request(url, method: .get, key, latitude, longitude).responseJSON
get的参数需要在url中,latitude
和longitude
也是double
的值,而不是Any