javascript - 使用 Openweathermap API 未找到 http 错误
问题描述
我正在尝试编写一个根据您当前位置显示温度的天气应用程序,使用 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);
});
});
我在控制台中遇到的错误:
解决方案
你没有达到他们的终点。由于您没有提供 URL 方案,因此它被识别为相对路径,并且您正在访问 localhost。
推荐阅读
- xcode-ui-testing - 使用 XCUIElement 上的谓词等待焦点
- vb.net - 如何在 Vb.Net 中隐式转换枚举类型
- excel - 删除 Excel 工作表中的特定行
- ionic-framework - Ionic 3 - 如何在禁用(透明)按钮后面移动内容
- angular - Ionic 3 中的数组等可迭代对象
- javascript - 查找浏览器生成的 javascript 变量的当前值
- javascript - 在物化中动态刷新 HTML 选择
- android - 如何从谷歌地图中删除多边形
- osgi - Fuse 7 中的 KIE 功能
- opengl - glsl 和 opencl 中的钳位功能如何工作?它使用创建分支吗?我应该避免使用它吗?