Contents
What are we going to build?
We are going to build a weather app that displays current conditions (temperature and icon) for a given zip code. The app will look like this:
Before you start
- Tutorial level: Beginner or your first mobile app
- Prerequisites: Tiggzi account
- The app uses API from World Weather Online. The API is free to use but requires registration in order to get a special API Key. Please register to get your key.
Creating new project
- To start, we are going to create a new app. Enter WeatherApp for app name and click Create.
- When the mobile builder loads, you should see something like this:
- On the left-hand side click Pages > startScreen - editor with an empty startScreen will open:
Creating mobile UI
- We are ready to build the UI. If you look at the phone, you will see Caption label at the top. That’s part of the header. Click on it and change the label to Weather App, to look like this:
- Now, from the Components section (on the left-hand side), drag and drop Label component into the screen. When a component that holds a text value dropped into a screen, its label goes into edit mode. Change the label to: Zip code. The result should look like this:
- Next, drag and drop Input component, right below the Label component. Delete its label text.
- Because we are going to reference this component when defining services, we should rename the component. Select the component and head to Properties. In Properties, change its name to: zipCodeInput.
- Drag and drop Button component and change its label to Get Weather. The result should look like this:
- If you want to change the spacing between each component, select the component and change its Margin property in Properties.
- We are done with input portion, now we need to create UI for displaying weather result. We are going to display the temperature and an image. Drag and drop a Label component below the button. Delete its label text.
- We will need to reference this component when we use services so it’s better to rename it. Select the component and head to Properties. In Properties, changes its Name to: temperature.
- The last component we are going to use is Image. Drag and drop Image component, below the label.
- In Properties, changes its default name mobileimage1 to icon.
- The final UI should look like this:
- One of the nice features in Tiggzi is that you can test the app and see how it looks in browser. Simply click Test button to open the app in browser).
- To view the app on mobile device, click the Test button.
- To test the app on the device, open Test and check Public, to make the app link public. Scan the QR code or email the link to your phone
Defining REST service
- We are ready to create a service which will connect to weather REST service. In Tiggzi app builder click Create New > Service.
- Rename the service to getWeather, click Create Service.
- A service editor will open:
- For service URL enter: http://free.worldweatheronline.com/feed/weather.ashx
- For Data type, select jsonp
- Click Save button and close service editor.
- Now that we are done defining service settings, next step is to define service inputs.
- Open Request panel
- This is where you define request parameters for the service. The weather service requires three parameters:
- q - zip code
- format - response format
- key - API key (get a free API key here).
- In the input field, enter q and click Add.
- Now create two more parameters, format and key. The result should look like this:
- For format, enter json as the Default value.
- For key, enter the API key as Default value.
- Let’s now test the service, go to Test tab, enter any zip code value for q.
- Click Test button. The result should look something like this:
- The next step is to define service response parameters. If you scroll through the test results, you will notice that the Weather REST service returns a large number of parameters. Creating them all by hand could be time consuming and error prone. Of course you can only define the parameters that you need. However, another solutions exits.
- Click Automatically Create Service Response button. This feature will automatically create the service response based on parameters present in sample test.
- You should see “Service response created successfully” message.
- Go to Response panel where listing all response parameters (after expending data and weather):
- We are done defining the service. Click Save and close getWeather service editor. Go to the startScreen > Data tab.
- From dropdown menu select Service > getWeather and click Add button.
Mapping UI and service
- Now we need to map UI to the service. Rename restservice1 to weather, click Edit Mapping for weather instance. Request Mapping should be selected by default.
- Define the mapping by selecting Text property and connecting it to q property on the service side. Both format and key are predefined.
- Now click on Response tab to map service output to UI.
- Define the following mappings:
- Click Save
Defining action to invoke the service
- One last thing left to do is invoke the service on button click. Go back to Design tab, open Events view (on the bottom of the screen).
- Select the button component (Click event is set by default) > from list select Invoke Service action > weather.
- Click Add event button.
- We are ready to test the app. Click Test button, enter any zip code and click Get Weather button.
Testing the app
Click the Test button to launch the app in the browser. The resulting app should look like this:
To test the app on the device, open Test menu and check Public. Scan the QR code or email the app link to your device. Learn about other ways to test an app.