단순한 날씨 애플리케이션을 구축 중이며 복잡하지는 않습니다. 사용자 위치를 기반으로 한 Open Weather Map에서 JSON을 가져와야합니다. 이것은 그러나,이 내 SWIFT 코드/Alamofire가 http://api.openweathermap.org/data/2.5/weather?appid=e72ca729af228beabd5d20e3b7749713&lat=52.516221&long=13.408363
은 그래서 URL보다는 그것의 끝의 시작 부분에 apiid=***
배치 나에게주는 것입니다Alamofire는 애플리케이션 API를 url의 끝 부분이 아닌 url의 시작 부분에 배치합니다.
WOM http://api.openweathermap.org/data/2.5/weather?lat=52.516221&lon=13.408363&appid=e72ca729af228beabd5d20e3b7749713
에서 JSON을 얻을 수있는 정확한 URL 구조입니다.
이것은 내 코드입니다.
let WEATHER_URL = "http://api.openweathermap.org/data/2.5/weather"
let APP_ID = "e72ca729af228beabd5d20e3b7749713"
func getWeatherData(url: String, parameters : [String : String]) {
Alamofire.request(url, method: .get, parameters: parameters).responseJSON {
response in
if response.result.isSuccess {
print ("Everything is fine")
print ( Alamofire.request(url, method: .get, parameters: parameters))
let weatherJSON : JSON = JSON(response.result.value!)
print (weatherJSON)
}
else {
print ("Error \(String(describing: response.result.error))")
self.cityLabel.text = "Connection issues"
}
}
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations[locations.count - 1]
if location.horizontalAccuracy > 0 {
locationManager.stopUpdatingLocation()
let latitude = "52.516221"
let longitude = "13.408363"
let params : [String : String] = ["lat" : latitude, "long" : longitude, "appid" : APP_ID]
getWeatherData(url : WEATHER_URL, parameters : params)
}
}
나는 작은 외모를 보지 않고 지금 울고 싶다. – Radu033