#1 2016-01-21 14:23:02

datadon
Member
Registered: 2015-04-23
Posts: 108

Weather App

Is there a way to change the temp from Centegrade to Farenheit ?  Are the factors setable like windspeed in mph?

Offline

#2 2016-01-21 15:14:16

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,661
Website

Re: Weather App

Hello Donald,

The Weather app sample use the Current Open Weather Map API, and, yes, that API provide us with certain Units options. For example, the below URL:

http://api.openweathermap.org/data/2.5/weather?appid=573b96a39548e971a8d4fdbb38ced5f1&q=Dallas,%20US&&units=metric

Retrieve information using the Standard metrics unit.

But this other URL:

http://api.openweathermap.org/data/2.5/weather?appid=573b96a39548e971a8d4fdbb38ced5f1&q=Dallas,%20US&&units=imperial

Retrieve the information using the Imperial units. So what we can do is to take in count the "units" argument in the URL, which can be "imperial" or "metric". If we simply omit this argument in the URL then the default units are "metric".

Online

#3 2016-01-22 04:09:56

datadon
Member
Registered: 2015-04-23
Posts: 108

Re: Weather App

Ok that makes sense but where do I change the string to show Imperial?   I cannot find it anywhere.

One of the problems I have is that code can be in so many different places I cannot find them.  Is there any place that all the code shows up?   Or anyway to search for a string in the app like "openweathermap.org" ?
Thanks

Is it part of this file?

http://www.davidesperalta.com/Humm/Site … eather.php

Last edited by datadon (2016-01-22 04:14:26)

Offline

#4 2016-01-22 04:17:40

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,661
Website

Re: Weather App

Hello Donald,

We can't use the Open Weather Map API directly from the application due to CORS limitations. So, how the application get the data from the API? The application uses a PHP script, who communicate with the Open Wheather API without CORS issues.

You can view such PHP script into the application folder and is in that PHP script in which we can view the Open Weather Map URL and then can add the appropiate argument (units) to it. If we plain to allow the application's user to change between units, then we must include in the application's HTTP call (used to retrieve the data) a new argument.

So the application inform to the PHP script to use the metric or the imperial unit. Probably I have sometime tomorrow in order to modify the Weather application sample in order to include the "units" option, then you can view how I implement it. Of course I take note about your suggestion. Of course a "global search engine" can be good, as well other things like a "code map". Good ideas.

Online

#5 2016-01-22 10:05:34

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,661
Website

Re: Weather App

Hello,

I forget to mention the Weather sample is a little special, in the sense that the first app's view (the home or main view) does not contain any button nor other control. In fact we use the view Show event with this code:

// Get a previously saved city name
GetOption "SavedCity" "[CurrentCity]"

If "[CurrentCity]" "!=" ""
  // Retrieve the city weather using an app's function
  GetWeatherData "[CurrentCity]"
Else
  // Allow the user to choose a city
  ReplaceView "ChangeView"
EndIf

And there is the "GetWeatherData" app's function, which is responsible to retrieve the information from the app's server, that is, from the Open Weather Map API. Below is the "GetWeatherData" app's function:

// Conform the appropiate URL
SetVar "[OpenWeatherBaseUrl]" "http://www.davidesperalta.com/Humm/Sites/Main/Views/Data/AppBuilder/Samples/Weather/weather.php?city=" "String"

HttpSetUrl "HttpClient" "[OpenWeatherBaseUrl][City]"

// And go ahead!
HttpExecute "HttpClient"

Above we can see how we conform the appropiate URL, including the city we want to retrieve their weather. At this point we must modify that code in order to add another argument (the "units") into the URL. Then our PHP script receive such arguments and perform the appropiate Open Weather Map API call.

Online

#6 2016-01-22 10:59:09

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,661
Website

Re: Weather App

Hello,

Update your App Builder copy Donald: I add a new "unit" option into the Weather app sample.

4u7oyoO.gif

Online

#7 2016-01-23 00:22:22

datadon
Member
Registered: 2015-04-23
Posts: 108

Re: Weather App

Hey that is great David.  Thanks for that.  You make me smile with your great service.
I am surely going to do something with this. 

Don

Offline

#8 2016-01-23 00:23:12

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,661
Website

Re: Weather App

My pleasure sir. smile

Online

Board footer

Powered by FluxBB


Copyright ©2018 DecSoft. All rights reserved.