WPF con la API de Google Weather que este en español

Sandra calvo ponce
24 de Abril del 2012
Hola a todos, tengo un código de una aplicación para poder poner etiempo en una pagina web, y soy incapaz de cambiar el idioma del XML de la Api de Google. Creo que es por no entender bien lo que hace el programa.

Me podríais ayudar, muchas gracias.


Imports System.Windows.Threading
Imports System.Threading

Class MainWindow

Private timer As DispatcherTimer
Private weatherDoc As XDocument
Private location As String
Private src As String
Private proceed As Boolean = False

Private Sub MainWindow_Initialized(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Initialized
timer = New DispatcherTimer
AddHandler timer.Tick, AddressOf timer_Tick
timer.Interval = New TimeSpan(0, 5, 0)
timer.Start()

' Fill the AutoCompleteBox collection.
SearchAutoTextBox.ItemsSource = My.Settings.UserLocations
End Sub

Private Sub MainWindow_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
Dim thread As New Thread(AddressOf WeatherConditions)
thread.Start()
End Sub

Private Sub GoButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles GoButton.Click
CheckAutoCompleteBox()
' Exit sub-procedure if textbox is empty.
If proceed = False Then
Exit Sub
Else
Dim thread As New Thread(AddressOf UserSpecifiedLocationForecast)
thread.Start()
End If
End Sub

Private Sub CloseButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles CloseButton.Click
Me.Close()
End Sub

Private Sub DragRect_MouseLeftButtonDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs)
Me.DragMove()
End Sub

' Create XDocument with data from Google weather API.
Private Sub WeatherConditions()
location = My.Settings.Location
src = "http://www.google.com/ig/api?weather=" & location "&hl="es

' Attempt to get xml data.
Try
weatherDoc = XDocument.Load(src)
Catch ex As System.Net.WebException
MessageBox.Show("Internet connection unavailable. " & _
"Unable to acquire latest weather info.", "Error!", _
MessageBoxButton.OK, MessageBoxImage.Error)
Exit Sub
End Try

'' Check for error from Google server.
'This portion of code will only execute if there's an invalid
'value in the location setting, something that shouldn't occur
'since only valid locations are saved in the location application
'setting on calls to UserSpecifiedLocationForecast method.
Dim problem = weatherDoc...(0)
If problem IsNot Nothing Then
MessageBox.Show("Unable to get the weather conditions of " & location & _
vbCrLf & "Try again and enter data in the format " & _
": city, country" & vbCrLf & "e.g. London, England", "Error")
' Clear textbox.
Me.Dispatcher.BeginInvoke(DispatcherPriority.Normal, New ThreadStart(AddressOf ClearSearchTextBox))
Exit Sub
End If

' Update UI elements.
Me.Dispatcher.BeginInvoke(DispatcherPriority.Normal, New ThreadStart(AddressOf CurrentConditions))
Me.Dispatcher.BeginInvoke(DispatcherPriority.Normal, New ThreadStart(AddressOf ForecastConditions))

End Sub

' Set the values of controls showing current weather conditions.
Private Sub CurrentConditions()
Dim currCondition = weatherDoc....Single() _
.Element("condition").@data

Dim temp_f = weatherDoc....Single() _
.Element("temp_f").@data

Dim temp_c = weatherDoc....Single() _
.Element("temp_c").@data

Dim humidity = weatherDoc....Single() _
.Element("humidity").@data

Dim imageSrc = "http://www.google.com" & weatherDoc... _
.Single().Element("icon").@data

Dim windCondition = (weatherDoc....Single() _
.Element("wind_condition").@data).Substring(6)

' Set text block values
cityTxtBlck.Text = My.Settings.Location
currConditionTxtBlck.Text = currCondition
temp_fTxtBlck.Text = temp_f & "° F"
temp_cTxtBlck.Text = temp_c & "° C"
humidityTxtBlck.Text = humidity
windSpeedTxtBlck.Text = windCondition

' Set image control image
Dim bi As New BitmapImage

bi.BeginInit()
bi.UriSource = New Uri(imageSrc)
bi.EndInit()

currConditionIcon.Source = bi
End Sub

' Set the values of controls showing the latest forecast conditions.
Private Sub ForecastConditions()
Dim dayOfWeek1 = weatherDoc...(0).Element("day_of_week").@data
Dim dayOfWeek2 = weatherDoc...(1).Element("day_of_week").@data

Dim low1 = weatherDoc...(0).Element("low").@data
Dim low2 = weatherDoc...(1).Element("low").@data

Dim high1 = weatherDoc...(0).Element("high").@data
Dim high2 = weatherDoc...(1).Element("high").@data

Dim condition1 = weatherDoc...(0).Element("condition").@data
Dim condition2 = weatherDoc...(1).Element("condition").@data

Dim imageSrc1 = "http://www.google.com" & _
weatherDoc...(0).Element("icon").@data
Dim imageSrc2 = "http://www.google.com" & _
weatherDoc...(1).Element("icon").@data

fcastDayTxtBlck1.Text = dayOfWeek1
fcastDayTxtBlck2.Text = dayOfWeek2

fcastLowTxtBlck1.Text = low1 & "° F"
fcastLowTxtBlck2.Text = low2 & "° F"

fcastHighTxtBlck1.Text = high1 & "° F"
fcastHighTxtBlck2.Text = high2 & "° F"

fcastConditionTxtBlck1.Text = condition1
fcastConditionTxtBlck2.Text = condition2

' Set images.
Dim bi1 As New BitmapImage
Dim bi2 As New BitmapImage

bi1.BeginInit()
bi1.UriSource = New Uri(imageSrc1)
bi1.EndInit()

bi2.BeginInit()
bi2.UriSource = New Uri(imageSrc2)
bi2.EndInit()

fCastIcon1.Source = bi1
fCastIcon2.Source = bi2
End Sub

' Get forecast and current weather conditions using location
' specified by user in the AutoCompleteBox.
Private Sub UserSpecifiedLocationForecast()
' Stop timer from updating controls.
timer.Stop()

' Attempt to load xml data from Google server.
Try
weatherDoc = XDocument.Load(src)
Catch ex As System.Net.WebException
MessageBox.Show("Internet connection failed. Ensure that you are" & _
" connected to the internet.", "Error", MessageBoxButton.OK, _
MessageBoxImage.Error)
Exit Sub
End Try

' Show the progressbar.
Me.Dispatcher.BeginInvoke(DispatcherPriority.Normal, New ThreadStart(AddressOf ShowProgressBar))

' Check for error returned by Google server.
Dim problem = weatherDoc...(0)
If problem IsNot Nothing Then
MessageBox.Show("Unable to get the weather conditions of " & location & _
vbCrLf & "Try again and enter data in the format " & _
": city, country" & vbCrLf & "e.g. London, England", "Error")
' Clear textbox.
Me.Dispatcher.BeginInvoke(DispatcherPriority.Normal, New ThreadStart(AddressOf ClearSearchTextBox))

' Hide the progressbar.
Me.Dispatcher.BeginInvoke(DispatcherPriority.Normal, New ThreadStart(AddressOf HideProgressBar))
Exit Sub
End If

' Save the location entered by the user as user's preferred
' location setting and add the location to the UserLocations
' collection.
My.Settings.Location = location
' Check whether location is already available in setting.
If My.Settings.UserLocations.Contains(location) True Then
My.Settings.UserLocations.Add(location)
End If
My.Settings.Save()

' Update UI elements.
Me.Dispatcher.BeginInvoke(DispatcherPriority.Normal, New ThreadStart(AddressOf CurrentConditions))
Me.Dispatcher.BeginInvoke(DispatcherPriority.Normal, New ThreadStart(AddressOf ForecastConditions))

' Clear textbox.
Me.Dispatcher.BeginInvoke(DispatcherPriority.Normal, New ThreadStart(AddressOf ClearSearchTextBox))
' Hide progress bar.
Me.Dispatcher.BeginInvoke(DispatcherPriority.Normal, New ThreadStart(AddressOf HideProgressBar))

' Restart timer.
timer.Start()

End Sub

Private Sub ClearSearchTextBox()
SearchAutoTextBox.Text = String.Empty
End Sub

' Check whether the user has entered a location in the AutoCompleteBox.
Private Sub CheckAutoCompleteBox()
If SearchAutoTextBox.Text String.Empty Then
location = SearchAutoTextBox.Text
src = "http://www.google.com/ig/api?weather=" & location
proceed = True
Else
MessageBox.Show("Enter a location in the location textbox.", "Weather")
proceed = False
End If
End Sub

Private Sub ShowProgressBar()
WeatherProgressbar.Visibility = Windows.Visibility.Visible
End Sub

Private Sub HideProgressBar()
If WeatherProgressbar.Visibility = Windows.Visibility.Visible Then
WeatherProgressbar.Visibility = Windows.Visibility.Hidden
End If
End Sub

Private Sub timer_Tick(ByVal sender As Object, ByVal e As EventArgs)
' Get the latest weather conditions every five minutes.
Dim thread As New Thread(AddressOf WeatherConditions)
thread.Start()
End Sub

Private Sub DragRect2_MouseLeftButtonDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles DragRect2.MouseLeftButtonDown
Me.DragMove()
End Sub
End Class