I have been working on my wardrobe application and added the weather feature a few days ago. I try to find time to finish the application, but it’s going slower than I wish it did. Last Saturday I moved to a new apartment and as I have been unpacking I have also sorted my clothes and the app would have been handy to have. Still need to find washable and small passive NFC tags so it’s faster to register laundry status on the item. If you know where I can find waterproof (washing machine proof!) tags please do let me know!
I thought I’d share with you how simple it is to get started with a weather API I came across, OpenWeatherMap. It’s free as long as calls per minute is below 60 plus Creative Commons license CC BY-SA 4.0 requirements. Double check this, as these things change with time and this post might not 😉
Let’s get started!
Create an account at OpenWeatherMap
Under API Keys you will find your default key- but you can generate more keys if you want to.
Now simply make the calls as specified in the documentation.
The rules are simple, the majority of the calls start with:
And after that follows the details, for example
and then a query string
and they should always contain the key:
APPID= [MY KEY]
I used JSON.Net to deserialize the data, after mapping the JSON to C# objects. With the latter I cheated- I grabbed the JSON data and then selected Edit => Paste Special => Paste JSON as classes in Visual Studio and voilá- I had the classes.
I then use Resharper and ‘Fix naming in file’ to get the naming to use the pascal case capitalization style. Then I use Resharper again to extract the types to their own classes in a folder.
There we go- weather in five minutes.