I'm currently coding a weather app, I'm copying it from a Udemy tutorial on swift.
I am currently in the process of getting the weather data, so I would like a request from Almofire as shown in the video.
as a beginner this is a bit difficult to explain so I just show the code:
import UIKit
import CoreLocation
import Alamofire
class WetterViewController: UIViewController, CLLocationManagerDelegate {
// MARK: Outlet
@IBOutlet weak var WetterImage: UIImageView!
@IBOutlet weak var temperatureLabel: UILabel!
@IBOutlet weak var StatusLabel: UILabel!
let WEATHER_URL = "http://api.openweathermap.org/data/2.5/weather"
let APP_ID = "3084f92d04fb27b6dd25f1a3a8afd221"
let locationManager = CLLocationManager()
override func viewDidLoad()
{
super.viewDidLoad()
// Latitude = Breitegrad
// longitude = Längengrad
//altitude = höhe
// accuray = genauigkeit
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters //Genauigkeit einstellen
locationManager.requestWhenInUseAuthorization() // Fragen ob position verwendet werden darf
locationManager.startUpdatingLocation() //Fängt an GPS location zu empfangen
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations[locations.count - 1]
print("Längengrad: \(location.coordinate.latitude)")
print("breitengrad: \(location.coordinate.longitude)")
let latitude = String(location.coordinate.latitude)
let longitude = String(location.coordinate.longitude)
let data : [String : String] = ["lat" : latitude , "lon" : longitude , "appid" : APP_ID]
}
func getWeatherData (url: String , data: [String: String]) {
Alamofire.request(url, method: .get, parameters: data) }
}