Ich baue eine einfache Wetteranwendung, nichts Kompliziertes, ich brauche nur die JSON von Open Weather Map basierend auf Benutzerstandort zu bekommen. Dies ist eine korrekte URL-Struktur die JSON von WOM http://api.openweathermap.org/data/2.5/weather?lat=52.516221&lon=13.408363&appid=e72ca729af228beabd5d20e3b7749713
Alamofire platziert die Anwendungs-API am Anfang der URL statt am Ende
jedoch zu bekommen, das ist, was meine SWIFT-Code/Alamofire gibt mir http://api.openweathermap.org/data/2.5/weather?appid=e72ca729af228beabd5d20e3b7749713&lat=52.516221&long=13.408363
so legt es die apiid=***
am Anfang der URL anstatt Ende.
Dies ist mein Code.
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)
}
}
Ich möchte jetzt weinen, nicht so ein kleines Problem zu sehen, danke Kumpel – Radu033