如何在PhoneGap中将Darksky API与json一起使用

时间:2019-02-23 21:32:44

标签: javascript html json api phonegap

我使用DarkSky API和JSON构建了功能全面的Web应用程序,还使用Jawg map API在地图上显示用户位置。 当加载到浏览器中时,它运行完美。 然后,我开始使用PhoneGap使其成为移动应用程序。 当我加载在浏览器中制作的PhoneGap应用程序时,它再次完美运行,但是当我将其加载到手机上时。 天气预报失败,但是令人惊叹的地图可以工作并显示用户的位置。

我在DarkSky API中缺少什么。 这是代码 这是问题所在...

navigator.geolocation.getCurrentPosition(position => {
            console.log(position);
            long = position.coords.longitude;
            lat = position.coords.latitude;

            const proxy = "http://cors-anywhere.herokuapp.com/";
            const api = `${proxy}https://api.darksky.net/forecast/{API-KEY}/${lat},${long}`;

            fetch(api)
                .then(response => {
                    return response.json();
                })
                .then(data => {
                    console.log(data);
                    const {
                        temperature,
                        summary,
                        icon,
                        humidity,
                        pressure,
                        windSpeed,
                        time
                    } = data.currently;

有什么帮助吗? 我知道代码有点长,但是请帮助

0 个答案:

没有答案