【发布时间】:2019-10-27 04:06:08
【问题描述】:
我正在尝试在另一个 api (https://api.wheretheiss.at/v1/coordinates/37.795517,-122.393693) 的 url 中使用 ISS api (https://api.wheretheiss.at/v1/satellites/25544) 上的纬度和经度坐标。我正在尝试使用坐标并在 url 中输入它们,而不是使用硬编码的。
这是我到目前为止所做的......
- 我尝试使用模板字符串来使坐标动态化:
https://api.wheretheiss.at/v1/coordinates/${latitude},${longitude} - 我创建了两个单独的异步等待函数:(1) getISS() 获取纬度/经度坐标和 (2) getGeoLocation() 获取这些坐标并获取 country_code/timecode_id 数据
- 我还尝试使用纬度、经度作为参数调用 getGeoLocation(),并将它们传递给参数的纬度和经度,但这只会导致 500 错误
注意
- 我知道这两个 url api 的工作,因为我已经对它们进行了测试并收到了我正在寻找的数据
- 这是api网站https://wheretheiss.at/w/developer
const api_url_id = 'https://api.wheretheiss.at/v1/satellites/25544'
//async await getISS function
async function getISS() {
const response = await fetch(api_url_id)
const data = await response.json()
const {
latitude,
longitude,
velocity,
visibility
} = data
}
async function getGeoLocation(latitude, longitude) {
const response2 = await fetch(`https://api.wheretheiss.at/v1/coordinates/${latitude},${longitude}`)
const data2 = await response2.json()
const {
timezone_id,
country_code
} = data2
console.log(data2.timezone_id,country_code)
}
getGeoLocation(data.latitude, data.longitude)
getISS()
【问题讨论】:
-
第二个请求获得 500 内部服务器错误,具有特定的经纬度...
标签: javascript function async-await geolocation fetch