Weather App


Donald Walker

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


DecSoft

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:

Retrieve information using the Standard metrics unit.

But this other URL:

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".



Donald Walker

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?

https://www.decsoftutils.com/Humm/Sites/Main/Views/Data/AppBuilder/Samples/Weather/weather.php


DecSoft

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.



DecSoft

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:

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:

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.



DecSoft

Hello,

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



Donald Walker

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


DecSoft

My pleasure sir. :)


Everybody can read the DecSoft support forum for learning purposes, however only DecSoft customers can post new threads. Purchase one or more licenses of some DecSoft products in order to give this and other benefits.

This website uses some useful cookies to store your preferences.

I agree. Hide this note. Give me more information.