I talked earlier about integrating WeatherBug data into Where's Tim. Chris Sloop has been a lot of help and was even nice enough to include Where's Tim on the WeatherBug's API example page. He requested that I share some code, so here it is:
Basically, to consume WeatherBug's API, I:
1) Make a call to the Where's Tim webservice
2) Parse the zipcode out of the .Place property of the GPSData structure
3) Pass the zipcode into a function that builds the REST url
4) Load the url into a System.Data.DataSet using the .ReadXML function
5) Pass that DataSet into my WeatherInfo structure that takes a DataSet as a constructor
Code to get location and parse zipcode:
Public Function GetTimsWeather() As WeatherInfo
Try
Dim CurData As GPSData = GetTimsLocation()
Dim ZipCode As String = CurData.Place.Remove(0, CurData.Place.Length - 5)
Return GetWBInfo(ZipCode)
Catch ex As Exception
Return Nothing
End Try
End Function
Code to build URL, load DataSet, and construct structure:
Private Function GetWBInfo(ByVal ZipCode As String) As WeatherInfo
Try
Dim url As String = "http://[myCode].api.wxbug.net/getlivecompactweather.aspx?acode=[myCode]&zipcode=" & ZipCode
Dim DS As New System.Data.DataSet
DS.ReadXml(url)
Dim RV As New WeatherInfo(DS, ZipCode)
Return RV
Catch ex As Exception
Return Nothing
End Try
End Function
Code of WeatherInfo structure constructor:
Public Sub New(ByVal DS As System.Data.DataSet, ByVal ZipCode As String)
Try
_temp = DS.Tables("temp").Rows(0).Item("temp_Text")
_rain = DS.Tables("rain-today").Rows(0).Item("rain-today_Text")
_wind = DS.Tables("wind-speed").Rows(0).Item("wind-speed_Text")
_winddirection = DS.Tables("weather").Rows(0).Item("wind-direction")
_zipcode = ZipCode
_weblink = "http://web.live.weatherbug.com/Common/home.aspx?zip=" & _zipcode
Catch ex As Exception
End Try
End Sub
Also, the WeatherBug API is now listed
ProgrammableWeb.com's API list and so is the
Where's Tim webserviceI've also integrated the WeatherBug data into
Where's Tim Mobile.