0

I want the weather report of a current location based on the latitude and longitude. Here is my code for the same:

void getData() async{
    print("hello");
    http.Response response = await http.get('https://api.openweathermap.org/data/2.5/weather?lat=$lat&lon=$lon&appid=$apis');
    print(response.statusCode);
    if(response.statusCode==200){
      String data = response.body;
      int id = jsonDecode(data)['weather'][0]['id'];
      double temperature = jsonDecode(data)['main']['temp'];
      String city = jsonDecode(data)['name'];
      print(id);
      print(temperature);
      print(city);
    }

    print(response.body);
  }

While running the app, i got this following error, but i had following the instructions properly and used the api provided by the web site
{"cod":401, "message": "Invalid API key. Please see http://openweathermap.org/faq#error401 for more info."}

4

0 回答 0