如何从openweathermap获取数据 [英] how to get wather data from openweathermap

查看:666
本文介绍了如何从openweathermap获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我需要从www.openweathermap.org获取信息。


我在google中发现这个类但是它不起作用idk为什么

 Imports System.Xml 
Imports System.Net

Public Class Weather_API
Private lpCity As String
Sub New( ByVal City As String)
lpCity = City
End Sub
公共函数Get_Weather()As String
Dim x As New XmlDocument
Dim i As New WebClient
x.LoadXml(i.DownloadString(" http://api.openweathermap.org/data/2.5/forecast/daily?q ="& lpCity&"& mode = xml& units = metric" ))
Dim City As String =""
Dim Country As String =""
Dim lastupdate As String =""
Dim temp As String
Dim humidity As String
Dim clouds As String
Dim windspeed As String
For each xn As XmlNode in x.GetElementsByTagName(" name" )
City = xn.InnerText
Next
For each xn As xmlNode in x.GetElementsByTagName(" country")
Country = xn.InnerText
Next
for Each xn As XmlNode in x.GetElementsByTagName(" lastupdate")
lastupdate = xn.InnerText
Next
temp = x.GetElementsByTagName(" temperature")(0)。 Attributes(0).InnerText
humidity = x.GetElementsByTagName(" humidity")(0).Attributes(0).InnerText& "%"
clouds = x.GetElementsByTagName(" clouds")(0).Attributes(0).InnerText
windspeed = x.GetElementsByTagName(" windSpeed")(0).Attributes(0).InnerText &安培; " MPS" &安培; " /" &安培; x.GetElementsByTagName(" windSpeed")(0).Attributes(1).InnerText
Dim Full As String =" Country:" &安培;国家和地区" " &安培;城市与城市" - L.Update:" &安培; lastupdate& " - 湿度:" &安培;湿度& "温度:" &安培;温度与温度" °C - " &安培; "云:" &安培;云与云" - WindSpeed:" &安培; windspeed
返回完整
结束功能

结束等级

致电:

 Dim WA As New Weather_API(" Syria,Aleppo")
TextBox1.Text = WA.Get_Weather

请帮帮我

解决方案

要使其正常工作,您需要一个有效的API密钥:


http://www.openweathermap.org/appid


hi guys, i need get wather information from www.openweathermap.org

i found this class in google but it's not work idk why

Imports System.Xml
Imports System.Net

Public Class Weather_API
    Private lpCity As String
    Sub New(ByVal City As String)
        lpCity = City
    End Sub
    Public Function Get_Weather() As String
        Dim x As New XmlDocument
        Dim i As New WebClient
        x.LoadXml(i.DownloadString("http://api.openweathermap.org/data/2.5/forecast/daily?q=" & lpCity & "&mode=xml&units=metric"))
        Dim City As String = ""
        Dim Country As String = ""
        Dim lastupdate As String = ""
        Dim temp As String
        Dim humidity As String
        Dim clouds As String
        Dim windspeed As String
        For Each xn As XmlNode In x.GetElementsByTagName("name")
            City = xn.InnerText
        Next
        For Each xn As XmlNode In x.GetElementsByTagName("country")
            Country = xn.InnerText
        Next
        For Each xn As XmlNode In x.GetElementsByTagName("lastupdate")
            lastupdate = xn.InnerText
        Next
        temp = x.GetElementsByTagName("temperature")(0).Attributes(0).InnerText
        humidity = x.GetElementsByTagName("humidity")(0).Attributes(0).InnerText & "%"
        clouds = x.GetElementsByTagName("clouds")(0).Attributes(0).InnerText
        windspeed = x.GetElementsByTagName("windSpeed")(0).Attributes(0).InnerText & "MPS" & " / " & x.GetElementsByTagName("windSpeed")(0).Attributes(1).InnerText
        Dim Full As String = "Country : " & Country & " " & City & " - L.Update : " & lastupdate & " - Humidity : " & humidity & " Temperature : " & temp & " °C -" & " Clouds: " & clouds & " - WindSpeed : " & windspeed
        Return Full
    End Function

End Class

call:

 Dim WA As New Weather_API("Syria,Aleppo")
        TextBox1.Text = WA.Get_Weather

please help me

解决方案

To get it to work you need a valid API key:

http://www.openweathermap.org/appid


这篇关于如何从openweathermap获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆