Access data online, parse it and display

31 views
Skip to first unread message

Diogo Pata

unread,
May 22, 2016, 9:36:44 PM5/22/16
to Protocoder
Thought about sharing a simple app to access data from a server and display it on the phone. 
In this example we get data regarding bikes availability from Bicing (Barcelona) and display our favourite stations. 


ui.toolbar.show(false);
ui.backgroundColor(100,100,100);

var myURL = "http://wservice.viabicing.cat/v2/stations"; //Define url you wanna get data from
network.httpGet(myURL, function(status, response) {

    var ourBike = JSON.parse(response);  // Parse string into JSON format (if your data allows to)
   var ttt = "Address  -  Slots   -   Bikes  \n\n";   // Lets find how many bikes we can find in our favorite bicing stations in Barcelona
   for(var ii=0; ii<ourBike.stations.length; ii++)
   {
       var idd =  parseInt(ourBike.stations[ii].id);
       if(idd==342 || idd==143 || idd==42)
       {
           ttt += ourBike.stations[ii].streetName +" - "+ ourBike.stations[ii].slots +" - "+ ourBike.stations[ii].bikes;
           ttt += "\n\n";
       }
   }
   var t = ui.addText(20, 30, 600, 600);  // Set the text to display.
   t.setText(ttt);
   t.textSize(25);    
});


Víctor Díaz

unread,
Sep 25, 2016, 1:42:43 AM9/25/16
to Protocoder
Thanks Diogo, nice example :)
I hope we can tweak your script for the new version that comes with gigantic changes! 

Feel free to join the beta program https://goo.gl/forms/az8yrACDRjsIGPm43

Cheers
Reply all
Reply to author
Forward
0 new messages