NWS Weather 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. 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 New Forecast-at-a-Glance icons and add them to Media.
Your part is to add more features to this app and share with the community.
Testing
The app was tested on a Samsung A13 Android 12 using both Companion and compiled.
Issues
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:
Mendapatkan lokasi terakhir yang diketahui | Developer Android | 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.
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 рождеством!, عيد ميلاد مجيد
Steve