WP7 city weather forecast Query

Source: Internet
Author: User

The last time I made a WP7 mobile phone crash location query, although I found a reference for it, but I still had a sense of accomplishment. So I studied the weather forecast for two days and made the following for a long time, but here I would like to express my feelings: it is very important to develop WP7 artists. Otherwise, as I said on the Internet, it is hard to develop WP7 artists .... A bunch of nonsense (although ugly, I have been playing the game for half a day)

You can directly enter the city or select the city. The background code is as follows:

/// <Summary>
/// Select a city
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private void btnadd_click (Object sender, routedeventargs E)
{
Navigationservice. navigate (New uri ("/citypage. XAML", urikind. relativeorabsolute ));
}
/// <Summary>
/// Query the weather
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private void btnseach_click (Object sender, routedeventargs E)
{
Navigationservice. navigate (New uri ("/wheatherpage. XAML? Cityname = "+ textbox1.text, urikind. relativeorabsolute ));
}
/// <Summary>
/// Return to the city
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private void phoneapplicationpage_loaded (Object sender, routedeventargs E)
{
If (navigationcontext. querystring. containskey ("cityname "))
{
Textbox1.text = navigationcontext. querystring ["cityname"];
}
}

Background code: during initialization, the XML file of a city is directly read to a ListBox for display.

Need to be improved and dynamic loading is not yet implemented. Background code

// Read the resource file. The file is in XML format. The building attribute of this file is resource.
Streamresourceinfo Sri = application. getresourcestream (New uri ("/searchwheather; component/citycode. xml ",
Urikind. Relative ));
// Read the data and save it to the result of the string type.
String result;
Using (streamreader sr = new streamreader (SRI. Stream ))
{
Result = Sr. readtoend ();
}

// Use the xdocument class to parse data
Xdocument Doc = xdocument. parse (result );

Here we can query the weather and temperature conditions of the city in the last four days, using Google's API;

Public void loadingdata ()
{
If (navigationcontext. querystring. containskey ("cityname "))
{
Cityname = navigationcontext. querystring ["cityname"];
}
Client. openreadasync (New uri ("http://www.google.com/ig/api? Hl = ZH-CN & OE = utf8 & weather = "+ cityname, urikind. relativeorabsolute ));
Client. openreadcompleted + = new openreadcompletedeventhandler (client_openreadcompleted );
}

Source http://download.csdn.net/detail/huangyuancao/4290653

Here for reference is Han Yifeng's blog inside the weather forecast blog address http://www.cnblogs.com/wildfeng/archive/2012/03/24/2415327.html

Also refer to blog http://blog.csdn.net/fengyun1989/article/details/7341703

Thank you for your help...

PS: I made two small programs for reference to others. I plan to think about myself as my own thing next.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.