Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Calling two APIs within the same Geolocation function

ANSWERED

I'm trying to call 2 APIs that require location as input (say for example 2 weathers provider). The 2 fetch functions are therefore included into the same response "locationSuccess(position)". 

My problem is very simple and I'm sure kinda stupid for developers but I'm very beginner: how do I merge the results returned by the 2 fetch before to send them back to the device?


I have something like 

fetch(ENDPOINT_weatherproviderlink1)
  .then(function (response) {
      response.json()
      .then(function(data) {
        // We just want some data
        var weather1 = {
          temperature: data["temp"]
        }
      });
  })
  .catch(function (err) {
    console.log("Error fetching weather: " + err);
  });
 };
fetch(ENDPOINT_weatherproviderlink2)
  .then(function (response) {
      response.json()
      .then(function(data) {
        // We just want some data
        var weather2 = {
          temperature: data["temp"]
        }
      });
  })
  .catch(function (err) {
    console.log("Error fetching weather: " + err);
  });
 };


// Send the weather data to the device returnWeatherData(weather);
// merge weather1 + weather2 ??????

 

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions
Best Answer
0 Votes
2 REPLIES 2
Best Answer
0 Votes

Thanks @JonFitbit. It definitely looks "promising" (see what I did here! Smiley Very Happy )However also very complex, time to put my head in the books!

Best Answer
0 Votes