I have location manager configured similar to how this post described How to get Current Location using SwiftUI, without ViewControllers? and I can see in the console that the lat and long are being returned.
However, when I when try to set the coordinates here I get back 0,0
class DownloadWeatherLocation: ObservableObject {
@Published var weatherlocationdata: [WeatherLocationDecoder] = []
let locationManager = LocationManager()
@AppStorage("userWID") var userWID = 0
@AppStorage("userLocationCity") var userLocationCity = ""
var weatherDataCancellabes = Set<AnyCancellable>()
init() {
I suspect the issue is in here.
print("WeatherLocation: loading init")
var userLatitude: String {
return "\(locationManager.lastLocation?.coordinate.latitude ?? 0)"
}
var userLongitude: String {
return "\(locationManager.lastLocation?.coordinate.longitude ?? 0)"
}
getWeatherLocation(weatherlocationUrl: "https://www.metaweather.com/api/location/search/?lattlong=\(userLatitude),\(userLongitude)")
}
... function that calls the URL which works, but uses 0,0
}