londonappbrewery / Clima-Flutter

Starter code for the Clima Project from the Complete Flutter Development Bootcamp
https://www.appbrewery.co
155 stars 741 forks source link

Error on Gathering API data using variables #26

Closed malikdanishalii closed 3 years ago

malikdanishalii commented 3 years ago

I am getting the API response when i put hardcoded values in Lon and lat but whenever i replace it with the variables that i declared it gives me the error 400. I have tried very hard to solve this but in vain kindly some one help me regarding this.

The code is here:

` void getData() async { var response = await http.get(Uri.parse( 'https://api.openweathermap.org/data/2.5/weather?lat=$latitude&lon=$longitude&appid=2a2ebb0a274ae93918a45df74879b8d6', )); 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);
}

}`

malikdanishalii commented 3 years ago

The error resolved by running the application on real / physical devices because emulator or simulator has the problem of getting real time location as per my knowledge and understanding after working for three days on this issue.