'b6907d289e10d714a6e88b30761fae22';
const apiKey = '2a2ebb0a274ae93918a45df74879b8d6';
class LoadingScreen extends StatefulWidget {
@override
_LoadingScreenState createState() => _LoadingScreenState();
}
class _LoadingScreenState extends State<LoadingScreen> {
double latitude;
double longitude;
@override
void initState() {
super.initState();
getLocation();
}
void getLocation() async {
Location location = Location();
await location.getCurrentLocation();
latitude = location.latitude;
longitude = location.longitude;
getData();
}
// Future<Location> getData() async {
// final response = await http.get(Uri.parse(
// 'https://api.openweathermap.org/data/2.5/weather?lat=90&lon=180&appid 2a2ebb0a274ae93918a45df74879b8d6',
// headers: {HttpHeaders.contentTypeHeader: 'application/json'}));
// if (response.statusCode == 200) {
// String data = response.body;
// var decodedData = jsonDecode(data);
// double temperature = decodedData['main']['temp'];
// int condition = decodedData['weather'][0]['id'];
// String cityName = decodedData['name'];
// print(temperature);
// print(condition);
// print(cityName);
// } else {
// print(response.statusCode);
// }
// }
void getData() async {
http.Response response = await http.get(Uri.parse(
'https://api.openweathermap.org/data/2.5/weather?lat=90&lon=180&appid=2a2ebb0a274ae93918a45df74879b8d6',
//headers: {HttpHeaders.contentTypeHeader: 'application/json'}
));
if (response.statusCode == 200) {
String data = response.body;
var decodedData = jsonDecode(data);
double temperature = decodedData['main']['temp'];
int condition = decodedData['weather'][0]['id'];
String cityName = decodedData['name'];
print(temperature);
print(condition);
print(cityName);
} else {
print(response.statusCode);
}
}
@override
Widget build(BuildContext context) {
getData();
return Scaffold();
}
}
The response is good but when I set the variable or lon value to longitude it gives the error of 400.
Обсуждают сегодня