我想通过传递 lat 和 log 从开放笼地理编码的承诺 aaray 中检索位置,但不知道如何检索值

问题描述

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

请帮帮我

解决方法

当使用 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))

第一行返回一个响应承诺。第二行包含有关如何解析响应正文的说明。在这种情况下,您想要解析 JSON,因此,您调用 res.json()。 有关后一部分的更多信息,请参见 here