UWP-058 - UWP Weather - Setup and Working with the Weather API

Play UWP-058 - UWP Weather - Setup and Working with the Weather API

The Discussion

  • User profile image

    Lower half of the screen turned dark after minute 24

  • User profile image
    Adam Hecktman

    I am not even a C# developer (a student in Java right now) and I found this incredibly valuable. Answered some questions I have had for a long time now. Thanks for putting out this series.

  • User profile image

    @kiko: Hmm... thanks for pointing that out ... I'm not sure what happened there.

  • User profile image

    @kiko: Bob made me aware of this, we are uploading a new version, may be an hour before it is corrected

  • User profile image

    @kiko: and we're updated with the new version Bob sent over :)

  • User profile image

    If someone has a problem to call API you may need to add


    to your url call. You well get your key after registration on OpenWeather.com .

  • User profile image

    When I run the UWP-058\UWPWeather project and click the Get Weather button, the following code causes and exception.

    RootObject myWeather =  await OpenWeatherMapProxy.GetWeather(

    Visual Studio is stating 'Geocoordinate.Latitude.get' is obsolete: Latitude may be altered or unavailable after Windows 8.1. Instead, use Point.Position.

    I have tried adding my own key (&appid=yourKey) to the end of var response = await http.GetAsync("http://api.openweathermap.org/data/2.5/weather?lat=32.77&lon=-96.79&units=imperial&appid="***myKey***"); on the OpenWeatherMapProxy class and that did not solve the problem.

    Changing the code to the following also did not work.

    Geoposition position = await LocationManager.GetPosition();
    await OpenWeatherMapProxy.GetWeather(

    Does anyone know how to solve this exception.

  • User profile image

    For me the sample code snippet doesn't work. Any one else with the same problem?


  • User profile image

    @zur: When you say "Visual Studio is complaining" ... Yes, Visual Studio will complain.  While that API has been deprecated, at the time of this recording there was no replacement that I was aware of.  The key is: does it COMPILE and run?  (It should ... that's my exact code).

    @Hemanzt: Could you be more specific?  I'll help if I can.

  • User profile image
    Ted Driver

    Are you aware that Visual Studio will do the JSON to C# conversion for you? Just copy the JSON as you did, and then create a new class file in Visual Studio. Then select Edit Menu|Paste Special|Copy JSON as classes. Works for XML too.

  • User profile image

    @Ted Driver: Doh!  Yes, now that you mention it I have heard that but clearly got stuck in my old ways.  Thank you!  I'll try to remember that next time.

  • User profile image

    Why on earth use the DataContractJsonSerializer and oblige yourself to write all this code and datacontract/datamember decorations (ugly stuff), and NOT use Newtonsoft.Json in one line (return JsonConvert.DeserializeObject<RootObject>(result);)? It's become industry standard nowadays. :)

    Still, great stuff Bob. Thanks a bunch for your effort.
    Great point Ted, didn't know this special paste function even existed. ;)

  • User profile image

    Thanks again for a great video Bob.

    ToyMaker, that is a great tip. You can replace 3 lines of code with just one.

                //var serializer = new DataContractJsonSerializer(typeof(RootObject));
                //var ms = new MemoryStream(Encoding.UTF8.GetBytes(result));
                //var data = (RootObject)serializer.ReadObject(ms);

    Replaced with:

    var data = JsonConvert.DeserializeObject<RootObject>(result);




  • User profile image

    I have to abandon yet again another try at coding. Followed it exactly.

    'System.Runtime.Serialization.Json.DataContractJsonSerializer' is a 'type' but is used like a 'variable'

    what does that mean??


  • User profile image

    How Can I use my own txt file with json format to add data like:

    {"city":"London","description":"overcast clouds",....}

    instead of using these

    var http = new HttpClient();
    var response =await http.GetAsync(string.Format(""));
    var result = await response.Content.ReadAsStringAsync();

    actualy how can I use txt file for data?


  • User profile image
    When i click the button i have the following error : NullReferenceException at the ResultTextBlock step.

     async void Button_Click(object sender, RoutedEventArgs e)

    RootObject myWeather = await OpenWeatherMapProxy.GetWeather(20.0, 30.0);
    ResultTextBlock.Text = myWeather.name + " - " + ((int)myWeather.main.temp).ToString() + " - " + myWeather.weather[0].description;

  • User profile image

    some of properties should be double. Such as "deg". Because the deg is decimal. That was the error for me.
    And the other thing; in the url, we should have an APPID

  • User profile image


    Yeah,... I was typing along and thinking, I don't normally have to do all this. ;)

    As a basic example, it's probably okay. If you were just starting out I can see why Bob would use it.

  • User profile image

    @BobTabor how can I indent gauge in this application, is there any library?

  • User profile image
    Great video presentations! I learnt a lot from watching them. I am trying to develop a weather api in vb.net. Can I develop a similar weather api using vb.net or will I have to incorporate xaml?

    Kind regards
  • User profile image
    Hi, not sure exactly what you're asking here. The API itself -- the part that supplies the data from the National Weather Service -- is implemented by someone else entirely. All I know is that they supply JSON with the data I want.

    I think you can now write vb.net apps for UWP, but I'm not 100% sure. I've not touched any of this stuff in years.

    My code that CALLS into the API and parses the results back into a .NET collection ... that part could be written in vb.net (I think).

    The XAML part is only the XML syntax that defines UI layout. However, in this video, the code behind that handles UI events like button clicks is written using C#, but could be vb.net (I think).

    Does that help?
  • User profile image
    Thanks, Bob, for the explanation. It helps.
  • User profile image
    Joel Benjamin

    Hi, My GetWeather in the line
    public async static Task<RootObject> GetWeather(double lat, double lon) has an error that says

    not all code paths return a value. how do i fix this?

Add Your 2 Cents