See below code:
I used Javascript to fetch latitude and longitude for displaying city name using Google-API. After successfully get lat and long when i call Google API just after below given API it will not displaying results.
if (navigator.geolocation){
navigator.geolocation.getCurrentPosition(position=>{
lat=position.coords.latitude;
long=position.coords.longitude;
const api=`https://cors.io/?https://api.darksky.net/forecast/API-KEY/${lat},${long}`;
fetch(api).then(response=>{return response.json()})
.then(data=> { console.log(data)
const {temperature}=data.currently
let celsius=(temperature-32)*(5/9)
alert(celsius)
})
//
})
}
First as API-KEY is missing in your endpoint.it should be replace with key.Hope so It will start working const api=https://cors.io/?https://api.darksky.net/forecast/API-KEY/${lat},${long}
;
You can call google api in the callback of your first api inside .then block like this:
fetch(api1).then(response => response.json()).
then(data => {
fetch(api2).then(res2 => res2.json());
});
Hope this helps!!