ایجاد سیستم وضعیت آب و هوا مانند گوگل (بخش اول)
نویسنده: شقایق اشتری
تاریخ: ۱۳۹۲/۱۲/۱۰ ۱۱:۳۰
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
[HttpGet]
public ActionResult Index()
{
ViewBag.ProvinceList = _RPosition.Positions;
ShowWeatherProvince(8);
return View();
} public ActionResult ShowWeatherProvince(int dpProvince)
{
XDocument rssXml=null;
CountryName CountryName = new CountryName();
if (dpProvince != 0)
{
switch (dpProvince)
{
case 1:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=2345768&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Azarbayejan-e Sharqhi" };
break;
}
case 2:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=2345767&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Azarbayejan-e Qarbi" };
break;
}
case 3:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=2254335&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Ardebil" };
break;
}
case 4:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=28350859&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Alborz" };
break;
}
case 5:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=2345787&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Esfahan" };
break;
}
case 6:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=2345775&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Ilam" };
break;
}
case 7:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=2254463&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Bushehr" };
break;
}
case 8:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=28350859&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Tehran" };
break;
}
case 9:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=2345769&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Chahar Mahall va Bakhtiari" };
break;
}
case 10:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=56189824&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Razavi Khorasan" };
break;
}
case 11:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=2345789&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Shomali Khorasan" };
break;
}
case 12:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=2345789&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Jonubi Khorasan" };
break;
}
case 13:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=2345778&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Khuzestan" };
break;
}
case 14:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=2255311&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Zanjan" };
break;
}
case 15:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=2345784&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Semnan" };
break;
}
case 16:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=2345770&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Sistan va Baluchestan" };
break;
}
case 17:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=2345772&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Fars" };
break;
}
case 18:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=20070200&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Qazvin" };
break;
}
case 19:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=2255062&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Qom" };
break;
}
case 20:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=2345779&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Kordestan" };
break;
}
case 21:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=2254796&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Kerman" };
break;
}
case 22:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=2254797&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Kermanshah" };
break;
}
case 23:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=2345771&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Kohgiluyeh va Buyer Ahmad" };
break;
}
case 24:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=20070201&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Golestan" };
break;
}
case 25:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=2345773&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Gilan" };
break;
}
case 26:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=2345782&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Lorestan" };
break;
}
case 27:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=2345783&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Markazi" };
break;
}
case 28:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=2345780&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Mazandaran" };
break;
}
case 29:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=2254664&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Hamedan" };
break;
}
case 30:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=2345776&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Hormozgan" };
break;
}
case 31:
{
rssXml = XDocument.Load("http://weather.yahooapis.com/forecastrss?w=2253355&u=c");
CountryName = new CountryName() { Country = "Iran", City = "Yazd" };
break;
}
}
ViewBag.Location = CountryName;
XNamespace yWeatherNS = "http://xml.weather.yahoo.com/ns/rss/1.0";
List<YahooWeatherRssItem> WeatherList = new List<YahooWeatherRssItem>();
for (int i = 0; i < 4; i++)
{
YahooWeatherRssItem YahooWeatherRssItem = new YahooWeatherRssItem()
{
Code = Convert.ToInt32(rssXml.Descendants("item").Elements(yWeatherNS + "forecast").ElementAt(i).Attribute("code").Value),
Day = rssXml.Descendants("item").Elements(yWeatherNS + "forecast").ElementAt(i).Attribute("day").Value,
Low = rssXml.Descendants("item").Elements(yWeatherNS + "forecast").ElementAt(i).Attribute("low").Value,
High = rssXml.Descendants("item").Elements(yWeatherNS + "forecast").ElementAt(i).Attribute("high").Value,
Text = rssXml.Descendants("item").Elements(yWeatherNS + "forecast").ElementAt(i).Attribute("text").Value,
};
WeatherList.Add(YahooWeatherRssItem);
}
ViewBag.FeedList = WeatherList;
}
return PartialView("_Weather");
} @{
ViewBag.Title = "Weather";
}
<link href="~/Content/User/Weather/Weather.css" rel="stylesheet" />
@section scripts{
<script src="@Url.Content("~/Scripts/jquery-1.6.2.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<script type="text/javascript">
$("#dpProvince").change(function () {
$(this).parents("form").submit();
});
</script>
}
<h2>Weather</h2>
<div id="Progress">
<img src="~/Images/User/Other/ajax-loader.gif" />
</div>
<div id="BoxContent"> @Html.Partial("_Weather")</div>
@using (Ajax.BeginForm(actionName: "ShowWeatherProvince", ajaxOptions: new AjaxOptions { UpdateTargetId = "BoxContent", LoadingElementId = "Progress", InsertionMode = InsertionMode.Replace }))
{
<div style="padding-top:15px;">
<div style="float:left; width:133px; ">Select Your Province</div>
<div style="float:left"> @Html.DropDownList("dpProvince", new SelectList(ViewBag.ProvinceList, "Id", "Name"),"Select Your Province", new { @class = "webUserDropDown", @style = "width:172px" })</div>
</div>
} @{
List<Weather.YahooWeatherRssItem> Feeds = ViewBag.FeedList;
}
<div>
@{
HtmlString StartTable = new HtmlString("<table class='WeatherTable' cellspacing='0' cellpadding='0'><tbody><tr>");
HtmlString EndTable = new HtmlString("</tr></tbody></table>");
HtmlString StartTD = new HtmlString("<td>");
HtmlString EndTD = new HtmlString("</td>");
}
<div style="width: 300px;">
@{
@StartTable
foreach (var item in Feeds)
{
@StartTD
<div>@item.Day</div>
<div>
@{
string FileName = "";
switch (item.Code)
{
case 0: { FileName = "/Images/User/Weather/Tornado.png"; break; }
case 1: { FileName = "/Images/User/Weather/storm2.gif"; break; }
case 2: { FileName = "/Images/User/Weather/storm2.gif"; break; }
case 3: { FileName = "/Images/User/Weather/storm2.gif"; break; }
case 4: { FileName = "/Images/User/Weather/15.gif"; break; }
case 5: { FileName = "/Images/User/Weather/29.gif"; break; }
case 6: { FileName = "/Images/User/Weather/29.gif"; break; }
case 7: { FileName = "/Images/User/Weather/29.gif"; break; }
case 8: { FileName = "/Images/User/Weather/26.gif"; break; }
case 9: { FileName = "/Images/User/Weather/drizzle.png"; break; }
case 10: { FileName = "/Images/User/Weather/26.gif"; break; }
case 11: { FileName = "/Images/User/Weather/18.gif"; break; }
case 12: { FileName = "/Images/User/Weather/18.gif"; break; }
case 13: { FileName = "/Images/User/Weather/19.gif"; break; }
case 14: { FileName = "/Images/User/Weather/19.gif"; break; }
case 15: { FileName = "/Images/User/Weather/19.gif"; break; }
case 16: { FileName = "/Images/User/Weather/22.gif"; break; }
case 17: { FileName = "/Images/User/Weather/Hail.png"; break; }
case 18: { FileName = "/Images/User/Weather/25.gif"; break; }
case 19: { FileName = "/Images/User/Weather/dust.png"; break; }
case 20: { FileName = "/Images/User/Weather/fog_icon.png"; break; }
case 21: { FileName = "/Images/User/Weather/hazy_icon.png"; break; }
case 22: { FileName = "/Images/User/Weather/2017737395.png"; break; }
case 23: { FileName = "/Images/User/Weather/32.gif"; break; }
case 24: { FileName = "/Images/User/Weather/32.gif"; break; }
case 25: { FileName = "/Images/User/Weather/31.gif"; break; }
case 26: { FileName = "/Images/User/Weather/7.gif"; break; }
case 27: { FileName = "/Images/User/Weather/38.gif"; break; }
case 28: { FileName = "/Images/User/Weather/6.gif"; break; }
case 29: { FileName = "/Images/User/Weather/35.gif"; break; }
case 30: { FileName = "/Images/User/Weather/7.gif"; break; }
case 31: { FileName = "/Images/User/Weather/33.gif"; break; }
case 32: { FileName = "/Images/User/Weather/1.gif"; break; }
case 33: { FileName = "/Images/User/Weather/34.gif"; break; }
case 34: { FileName = "/Images/User/Weather/2.gif"; break; }
case 35: { FileName = "/Images/User/Weather/freezing_rain.png"; break; }
case 36: { FileName = "/Images/User/Weather/30.gif"; break; }
case 37: { FileName = "/Images/User/Weather/15.gif"; break; }
case 38: { FileName = "/Images/User/Weather/15.gif"; break; }
case 39: { FileName = "/Images/User/Weather/15.gif"; break; }
case 40: { FileName = "/Images/User/Weather/12.gif"; break; }
case 41: { FileName = "/Images/User/Weather/22.gif"; break; }
case 42: { FileName = "/Images/User/Weather/22.gif"; break; }
case 43: { FileName = "/Images/User/Weather/22.gif"; break; }
case 44: { FileName = "/Images/User/Weather/39.gif"; break; }
case 45: { FileName = "/Images/User/Weather/thundershowers.png"; break; }
case 46: { FileName = "/Images/User/Weather/19.gif"; break; }
case 47: { FileName = "/Images/User/Weather/thundershowers.png"; break; }
case 3200: { FileName = "/Images/User/Weather/1211810662.png"; break; }
}
}
<img alt='@item.Text' title='@item.Text' src='@FileName'>
</div>
<div>
<span>@item.High°</span>
<span>@item.Low°</span>
</div>
@EndTD
}
}
@EndTable
</div>
</div> public static string GetFileName(int code)
{
switch (code)
{
case 0: return "/Images/User/Weather/Tornado.png";
//...
} public class YahooWeatherRssItem
{
public int Code { get; set; }
//...
public string FileName
{
get { return Util.GetFileName(Code); }
}
} select * from weather.forecast where woeid in (select woeid from geo.placefinder where text="CityName")
با سلام؛ در مطلب گفته شده برای گرفتن WOEID شهرها به فلان سایت بروید و هر کشوری رو بخواییم باید بریم و دستی واردش اما من دیتابیس یا هر چیز دیگری رو میخوام که قابلیت این رو داشته باشه که کاربر با وارد کردن کشور و شهر بتونه آب و هوا رو ببینه. شما میتونید راهنمایی ام کنید که چه کار باید بکنم و یا منبعی برای دیتابیس مختصات جغرافیایی کشورها وجود داره؟ ممنون میشم کمکم کنید. با تشکر