【问题标题】:Getting not found http error with Openweathermap API使用 Openweathermap API 未找到 http 错误
【发布时间】:2020-11-15 10:13:04
【问题描述】:

我正在尝试编写一个根据您当前位置显示温度的天气应用程序,使用 OpenWeatherApi,我收到错误 404 我不知道为什么

if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(position => {
      long = position.coords.longitude;
      lat = position.coords.latitude;
      console.log(position);
      const api = `api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${long}&appid=74913cd6ec927a299e7fd99534e17b5f`;
      fetch(api)
        .then(response => {
          return response.json();
        })
        .then(data => {
          console.log(data);
        });
    });

我在控制台中遇到的错误:

【问题讨论】:

  • 我看不出你的代码有什么问题。您确定 long/lat 和 appid 有效吗?
  • 我遇到了同样的问题。你刚刚为我解决了。贾保佑你

标签: javascript openweathermap


【解决方案1】:

你没有达到他们的终点。由于您没有提供 URL 方案,因此它被识别为相对路径,并且您正在访问您的本地主机。

【讨论】:

  • 谢谢,我怎样才能为他们的端点提供 URL 方案?
  • (请注意您的错误中显示“get http://127.0.0.1:5500/api”等)
猜你喜欢
  • 2016-01-10
  • 1970-01-01
  • 2017-07-28
  • 1970-01-01
  • 1970-01-01
  • 2017-07-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多