☂️ NWS 🌩️ Weather ❄️ App

fzra_sn :open_umbrella: NWS :cloud_with_lightning: Weather :snowflake: App

The U.S. National Weather Service (NWS) free API provides weather information and forecasts throughout the United States. A small example app shows how to extract the provided weather information and build a travel weather app that will always provide the appropriate basic local weather information but only for the United States. Display lots of more information (in addition to the basic weather data provided using the techniques that allow you to extract the basic data) if you provide the additional features. Yes, you have to do this coding. :slight_smile: to provide forecasts and other features.

Users inside the U.S.
Coordinates from a LocationSensor and your GPS receiver tells the weather service api where you are located to ensure you retrieve local weather conditions. A WIFI or data connection is required to use the api and download information. A link to this main version of the app is below.

Users outside the U.S.
Users outside the U.S. unfortunately cannot use your actual location information to provide a local forecast in whatever country they are in. The api is not worldwide weather forecast. A version of the aia for you developers is provided. Users outside the USA get a forecast for anywhere in the USA for which you provide coordinates and a Button. The app also provides a List of coordinates using a ListPicker to do the GET. The code certainly can be improved.
The example aia shows a way to access a single location forecast and a way to use a ListPicker to select various locations in the USA for users not present in the USA.
NWSweatherAppNonUS.aia (505.5 KB)

How it works
The api requires two step authorization. Use an a user-agent with the GET control that actually retrieves the weather information as a json. The json is downloaded and converted to a dictionary. The dictionary makes it very easy to capture individual weather data such as temperature, humidity, barometric pressure etc.

NWS forecast icons used in the app are from the NWS. The app has a download of a lot of the NWS forecast icons in the app Media. Perchance you need more, capture them from https://www.weather.gov/forecast-icons and add them to Media.

Your part is to add more features to this app and share with the community.


The app was tested on a Samsung A13 Android 12 using both Companion and compiled.

There are several ways to handle the GPS hardware on Android 11+ devices using App Inventor. One way is to force the Provider to gps. Eliminate that part of the code and you can use the fused Provider in Android 11+ devices. Defaulting to fused probably may result in greater lag time getting the app to respond initially. Experiment and use the method that suits you. Devices earlier than Android 11, I believe, do not have Google's fused feature.

See a discussion of the fused Provider in the following links:

Get the last known location  |  Android Developers

A discussion in the community:

GPS with Android 12 - #39 by SteveJG This quote from the link "The COARSE/FINE permission change will be in the 2.65 companion update later this month to address Android 12 compatibility. " did not seem to make it into the Companion 2.65. The compatibility adjustment does not really address the GPS issues of stability nor correctly manage a fused Provider.

The existing MIT LocationSensor is not capable of effectively managing fused Provider. It lacks the required Methods. App Inventor currently manages (?) this using the above work around.

Do you get this runtime error? The aia was replaced with a version that fixed the issue 12/23. :astonished:

edit: This was fixed 12/23. :astonished: Runtime Error no longer occurs.

Will this run on other Android versions? I don't know. Experiment. You have the aia.
NWSweatherApp.aia (543.3 KB) (edited to remove loading error message)

Will this run outside the USA? No, not from the aia as it is. You have to modify the code and only then get forecasts for targeted areas in the US. See the NWSweatherAppNonUS aia posted above for a version that can be run from outside the US.

Merry Christmas, Wesołych Świąt, Feliz Navidad, God Jul, Joyeux Noel, Καλά Χριστούγεννα, Happy Christmas, Veseloho Rizdva, Prettige Kerstdagen, Frohe Weihnachten!, 성탄 축하 , Buon Natale, 聖誕快樂 , 圣诞快乐, Sretan Božić, C рождеством!, عيد ميلاد مجيد



Maybe this could help

Try using a screen1.ErrorOccured and put a "evaluate but ignore result" then any operator (like 1+1). This may make the app ignore errors.

Thank you Tyler @busybird15

  • your suggestion, that some times magically works by hiding non-fatal error messages, unfortunately did not work. :cry:

  • however, a modification of d_Taraoa's work around, does eliminate the error message. Thank you Taraoa.. :slight_smile: I will post the revised Blocks and aia after I clean up the code some time tomorrow. Users wanting to play can still ignore the message by touching the Screen anywhere but on the message and the app will work. For others I will post tomorrow the revised code.

The articles was revised on 12/23 to aia replace the problem code . A version of the app for potential users outside the USA. was also added.

Okay, I see.
I've done that before and figured it would work in your instance, but it doesn't.

You can also tap the back button on the navigation bar.

1 Like

@SteveJG Would it be more efficient if you have a procedure reused for your set Label.Text blocks, and using the for each item in list block?

Hi Gordon.

It might be possible to use a looping Procedure but why bother? There are only 14 get value at key path calls.

I added an aia version of the app for developers outside the USA this morning. You might want to see whether you can improve and refactor the existing Procedure. It is certainly possible. Why not try and share your findings.

There are several other ways the NWS api json can be stripped for weather information using other dictionary blocks or by using a simple List instead of a Dictionary.

You (and everyone) are welcome to share your coding ideas. The basic app can be made more useful if the forecast part of the api were utilized. I enjoyed coding this as simply as possible but realize it could be improved. However that is work and I am a bit lazy this holiday season.

Here is what the app could look like:

The challenge is to add forecast before the New Year. :slight_smile: I think some of you might find improving this a lot of fun and a challenging learning experience. This is a complex api and I only showed how to code a small part.

Best wishes.


1 Like

Thanks for extension link :slight_smile: . Fused not necessary in the app as it is. App does not require an extension. gps works fine.