I need some help created a google weather api using vb .net.

I found the code online and there are no errors. Problem is that I can't seem to display wether information. Nothing shows up on screen and I am not sure what I did wrong. any ideas?

Imports System.Net

Partial Class UI_MasterPage
    Inherits System.Web.UI.MasterPage


    Protected Sub SearchIB_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles SearchIB.Click
        Dim WeatherData As New Weather.WeatherInfo_Typed
        WeatherData = Weather.Grab_Weather("texas")
        temp.InnerHtml &= WeatherData.location & "--" & WeatherData.forcast_date & "--" & WeatherData.checked_time_date & "--" & WeatherData.humidity & "--" & WeatherData.forcast_date 
    End Sub
End Class


<Runtime.CompilerServices.Extension()>
Module Weather

    Public Structure WeatherInfo_Forecast
        Dim DayOfWeek As String
        Dim low As Double
        Dim high As Double
        Dim icon As String
    End Structure

    Public Structure WeatherInfo_Wind
        Dim direction As String
        Dim speed As Double
        Dim unit As String
    End Structure

    Public Structure WeatherInfo_Typed
        Dim Failed As Boolean
        Dim errormessage As Exception
        Dim location As String
        Dim forcast_date As DateTime
        Dim checked_time_date As DateTime
        Dim humidity As Double
        Dim highf As Double
        Dim lowf As Double
        Dim highc As Double
        Dim lowc As Double
        Dim currenttempC As Double
        Dim currenttempF As Double
        Dim predicted_icon As String
        Dim current_icon As String
        Dim current_condition As String
        Dim predicted_condition As IEnumerable(Of WeatherInfo_Forecast)
        Dim wind_condition As WeatherInfo_Wind
        Dim day As String
    End Structure

    <Runtime.CompilerServices.Extension()> _
    Public Function ToC(ByVal F As Double) As Double
        Return ((F - 32) / 9) * 5
    End Function

    <Runtime.CompilerServices.Extension()> _
    Public Function TryParseAsDouble(ByVal s As String) As Double
        Dim rv As Double
        If Double.TryParse(s, rv) = False Then rv = Double.NaN
        Return rv
    End Function

    <Runtime.CompilerServices.Extension()> _
    Public Function TryParseAsDate(ByVal s As String) As DateTime
        Dim rv As DateTime
        If DateTime.TryParse(s, rv) = False Then rv = Nothing
        Return rv
    End Function

    Private Function ParseHumidity(ByVal s As String) As Double
        If Not s Is Nothing Then
            Dim humRegEx As New System.Text.RegularExpressions.Regex("Humidity: (?<Value>\d+)\w*\%")
            Dim m = humRegEx.Match(s)
            If m.Length = 0 Then Return Double.NaN
            Return Double.Parse(m.Groups("Value").Value)
        End If
    End Function

    Private Function ParseWind(ByVal s As String) As WeatherInfo_Wind
        Dim rv As New WeatherInfo_Wind
        If Not s Is Nothing Then
            Dim humRegEx As New System.Text.RegularExpressions.Regex("Wind\:\s+(?<Direction>[NEWSnews]{1,2})\s+at\s+(?<speed>(?<value>\d+)\s(?<units>\w+)){1}")
            Dim m = humRegEx.Match(s)
            rv.speed = Double.NaN
            If m.Length = 0 Then Return rv
            With rv
                .direction = m.Groups("Direction").Value
                If Double.TryParse(m.Groups("value").Value, .speed) = False Then .speed = Double.NaN
                .unit = m.Groups("units").Value
            End With
        End If
        Return rv
    End Function


    Public Function Grab_Weather(ByVal Location As String) As WeatherInfo_Typed
        Dim GrabWeather As New WeatherInfo_Typed
        With GrabWeather
            .Failed = True
            Try
                Dim xml As XDocument = XDocument.Load("http://www.google.com/ig/api?weather=" & Location)
                Dim xp = xml.<problem_cause>
                If xp.Any Then Return GrabWeather
                .location = xml...<city>.@data
                .forcast_date = xml...<forecast_date>.@data.TryParseAsDate
                .checked_time_date = xml...<current_date_time>.@data.TryParseAsDate
                .humidity = ParseHumidity(xml...<humidity>.@data)
                .highf = xml...<high>.@data.TryParseAsDouble
                .lowf = xml...<low>.@data.TryParseAsDouble
                .highc = GrabWeather.highf.ToC
                .lowc = GrabWeather.highc.ToC
                .currenttempC = xml...<temp_c>.@data.TryParseAsDouble
                .currenttempF = xml...<temp_f>.@data.TryParseAsDouble
                '.current_icon = "http://www.google.com" & xml...<icon>.@data
                '.predicted_icon = "http://www.google.com" & xml...<high>.@data
                .current_condition = xml...<condition>.@data
                .predicted_condition = From f In xml...<forecast_conditions> _
                                    Select New WeatherInfo_Forecast With { _
                                      .DayOfWeek = f.<day_of_week>.Value, _
                                      .high = f.<high>.@data.TryParseAsDouble, _
                                      .low = f.<low>.@data.TryParseAsDouble}
                '.icon = "http://www.google.com" & f.<icon>.@data}
                .wind_condition = ParseWind(xml...<wind_condition>.@data)
                .day = xml...<day_of_week>.@data
                .Failed = False

                Return GrabWeather
            Catch ex As Exception
                .errormessage = ex

                Return GrabWeather
            End Try
        End With
    End Function
End Module

Dani AI

Generated

Short answer up front: this almost certainly isn't a VB runtime bug — it’s the source. The XML endpoint used by many old examples was never a supported public API (it was the iGoogle widget feed) and Google phased iGoogle out; by 2012–2013 developers started seeing 403 / "Unsupported API" responses. Expect that endpoint to be intermittent or gone; confirm by loading the same URL in a browser or curl. (blog.google)

Follow these practical checks (quick, low-effort diagnostics):

  • Verify the button event runs and the server control temp actually exists on the page (make sure it has runat="server" / a designer declaration). pointed this out and it is an easy thing to rule out before deeper debugging.
  • Inspect the WeatherData object: Grab_Weather sets .Failed = True up front and only clears it on success. Dump or log WeatherData.Failed and WeatherData.errormessage to see any exceptions thrown by XDocument.Load.
  • Hit the feed URL manually (browser, curl, Fiddler) and check the raw response for "Unsupported API" or HTTP 403/timeout — that tells you the provider side is the problem, not your parsing.

Small code/logic notes to check while you have the project open: there’s an apparent typo where lowc is computed from highc instead of lowf (so Celsius low may be wrong). Also avoid hitting an unstable endpoint on every click — cache results for a reasonable interval while you diagnose.

If the feed is dead, move to an official API. Popular choices: OpenWeatherMap (global, API key, well-documented), the US National Weather Service API (free, no key, US-only), or Google’s modern Weather product on the Maps Platform if you want Google-backed data. Each has documentation and stable support to build against. (idratherbewriting.com)

Checklist: confirm control exists, log WeatherData.Failed/errormessage, test the URL raw, then either fix local bugs or switch to a supported weather API and add simple caching.

From a quick perusal, I see, you're using an object(temp) that doesn't appear to be instantiated anywhere.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.