Geeks With Blogs

News



Add to Google

Tim Hibbard CEO for EnGraph software

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 webservice

I've also integrated the WeatherBug data into Where's Tim Mobile.

Posted on Friday, January 13, 2006 7:51 AM .NET , Where's Tim | Back to top


Comments on this post: Working with WeatherBug API

# re: Working with WeatherBug API
Requesting Gravatar...
hi,
In order to includ ethese methods do i need to integrate any dll in my application if so if you could provide me the dll then it will be a great help to me.
regards,
krishna
Left by vamsi on Jul 21, 2009 1:42 AM

# re: Working with WeatherBug API
Requesting Gravatar...
@krishna
Tim make the integration with his application which, probably, uses certain libraries. For your specific application, take the integration part and just use it like that, for your custom app, said bijuterii din argint.
Left by Georgy on Aug 02, 2011 7:56 AM

# re: Working with WeatherBug API
Requesting Gravatar...
HI,
I am workin on similar API,
is there any way i can decide that the wather is sunny, or partially clody, or rainy or clody etc so that i can put dynamic weather images based on that?
Left by amul on Sep 17, 2011 4:16 PM

# re: Working with WeatherBug API
Requesting Gravatar...
hi can i get lightning alert.(lattitude,longittude,PeakAmplitude,date and time) of lightning...?if any one know reply me..
Left by pullareddy on May 13, 2013 9:12 AM

Your comment:
 (will show your gravatar)


Copyright © Tim Hibbard | Powered by: GeeksWithBlogs.net | Join free