Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on Gathering API data using variables #26

Closed
malikdanishalii opened this issue Sep 11, 2021 · 1 comment
Closed

Error on Gathering API data using variables #26

malikdanishalii opened this issue Sep 11, 2021 · 1 comment

Comments

@malikdanishalii
Copy link

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant