【问题标题】:i want to retrieve location from promise aaray of open cage geocoding by passing lat and log but dont know how to retrieve the value我想通过传递 lat 和 log 从 opencage 地理编码的 promise 数组中检索位置,但不知道如何检索该值
【发布时间】:2021-06-29 15:57:14
【问题描述】:

我想从获取的开放笼式地理编码 API 中检索位置,该 API 具有以下结构 this picture contains the structure of data strogae

请帮帮我

【问题讨论】:

  • 你是如何获取数据的?拿来? Axios?
  • fetch(https://api.opencagedata.com/geocode/v1/json?q=${Latitude}+${Longitude}&key=############################) @Patric

标签: javascript reactjs promise geolocation reverse-geocoding


【解决方案1】:

当使用 fetch 你通常可以这样完成它:

fetch("https://api.opencagedata.com/geocode/v1/json?q=51+16&key=YOUR_KEY")
    .then( response => response.json())
    .then( data => console.log(data.results))

第一行返回一个响应 Promise。第二行包含有关如何解析响应正文的说明。在这种情况下,您想要解析 JSON,因此,您调用 res.json()。 后半部分的更多内容可以查看here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-15
    • 2018-08-26
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    相关资源
    最近更新 更多