I’m Aidan Wolf, VP of Product at Datazar. I’m going to show you how to use the Datazar API and Corona SDK to build a cross-platform airport wifi finder in 49 lines of code. (Source code below.)

First, go to datazar.com > settings > tokens > create new token

Second, download Corona SDK, it’s free! Install, open, and select Create New Project

Name your project and press Next, then save the project and open up Main.lua in your favorite text editor. Note: Main.lua is the only file we’ll need to open to complete the project — let’s get started!

The dataset we need is already available on Datazar so we just need to copy the File API Endpoint and we’re ready to go.

https://api.datazar.com/files/f492bcc6b-478b-4a72-8947-6840016711fc/data

For future reference, the File API Endpoint is found here:

Now just paste the endpoint into Main.lua like so:

Then add the token you generated earlier as api_token, and add your Datazar username as api_user.

And set up your parameters like so. If you get an “Authorization Failed” response from Datazar, this is likely where you went wrong.

Request and response in <10 lines of code.

getFile is our callback function for the network.request, which receives the entire response as “event”. Within event is response, aka, our sweet, sweet json data.

Press CMD + R to run the Corona Simulator. If we did this right, we should get a response from the Datazar API just like this:

Response from the Datazar API.

The original file was uploaded as a CSV and returned as JSON (Great, right?) but notice the column names are not converted into keys, they are stored in the first subschema.

Below, I decoded the JSON data to make it usable, I pulled out that first subschema as columnNames, and I then created a loop that prints the data with key values attached. You do not need to do this for the final app.

Corona SDK has some really powerful built-in APIs to make development faster, one of them is Location (GPS). Read the docs for details.

Under getFile, add the following code. In these few lines we’re getting location permission from the user and receiving location data. Notice the network.request call from earlier was put within the locationHandler.

The _G. in front of latitude and longitude stands for global, meaning we can access these variables anywhere in our project. Good for later.

This is our final getFile function. Here, we are looping through all our data and comparing two distance functions to find the nearest airport.

Once the loop is complete, closestWifi is sent to displayWifiInformation, a new function we add above getFile. This function displays 4 lines of text using display.newText, with various styling options.

Press CMD + R to run the Corona Simulator — You should see the closest airport proudly displayed on the screen. Congratulations!

Our app FlyFi, running on both Apple and Android hardware.

If you found this post helpful and want to see more like it, make sure to like and comment below. Thank you for reading, see you next time.

FlyFi Project Source Code