Anthony Berko
Posts: 0
Joined: Thu Oct 23, 2014 9:04 am

Loop weather app for multiple locations

Hi Guys

I am building a weather section into my app and have followed the tutorial for using World Weather Online API. I can successfully search a single location and have it fill a grid element. I have also managed to get the response to give a 5 day forecast for a single location using the API. However...

Image

Image

However I would like it to continue filling the grid with multiple locations either from an array of locations or another database of locations (i think the array would be easier). I have tried making an array and adding a loop in JS mapping query but as I suspected it only returns the first Array Item and finishes the query.

When I test the response for multiple locations query separated by a semicolon ; it returns all the data for each location but I cant get it to fill the grid element on my page with all the data for each location one after the other.

Image

Can you please help, have been at it for days now
Here is my code that doesn't do the job...

Image

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Loop weather app for multiple locations

Hello Anthony,

Please run the service in a loop:
https://devcenter.appery.io/documenta...

instead of using the loop inside of the request parameter.

Anthony Berko
Posts: 0
Joined: Thu Oct 23, 2014 9:04 am

Loop weather app for multiple locations

Hi Sergiy

I have tried the following loop to search weather based on array 'Locations'.

for (var i = 0; i < 5; i++) {
var Locations = ["Goulburn, Australia", "Bendigo, Australia", "Caloundra, Australia", "Hobart, Australia", "Melton, Australia"];
var Lookup = Locations;
localStorage.setItem('LocationWx', Lookup);
GetWeatherList.execute();
}

I have mapped the local storage variable 'LocationWx' to the query 'q'. Every loop is saving a new location to the storage variable then executing the service. Unfortunately the grid that receives the success mapping seems to be displaying weather for a random location everytime the javascript below is run. It will only display one weather location but not multiple??

Anthony Berko
Posts: 0
Joined: Thu Oct 23, 2014 9:04 am

Loop weather app for multiple locations

Hi Sergiy

Turns out I didnt need to write my own loop in JavaScript. I was using incorrect mapping from weather database to grid. In the end i needed to put a grid within another grid if that makes any sense.

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Loop weather app for multiple locations

Thanks for the update, Anthony!

Mike C
Posts: 0
Joined: Sun Dec 20, 2015 9:43 pm

Loop weather app for multiple locations

Hey Anthony, I'm trying to do something similar - make multiple calls to a 3rd party API based on an array of data acting as individual parameters for each call. Would you mind sharing your solution? I can't figure it out. Thanks!

Return to “Issues”