Closed benjymous closed 11 years ago
Looks like a bug of the URL. Maybe the ',' was removed before sending the URL to Google. Need to check that in the history.
The space character is the problem in location "DALLAS, US". "DALLAS,US" is working fine.
07-19 14:19:20.231: E/MetaWatch(5136): Exception while retreiving weather
07-19 14:19:20.231: E/MetaWatch(5136): java.lang.IllegalArgumentException: Illegal character in query at index 44: http://www.google.com/ig/api?weather=Dallas, US
07-19 14:19:20.231: E/MetaWatch(5136): at java.net.URI.create(URI.java:776)
07-19 14:19:20.231: E/MetaWatch(5136): at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:75)
07-19 14:19:20.231: E/MetaWatch(5136): at org.metawatch.manager.weather.GoogleWeatherEngine.update(GoogleWeatherEngine.java:81)
07-19 14:19:20.231: E/MetaWatch(5136): at org.metawatch.manager.Monitors$1.run(Monitors.java:255)
Proposed fix: Shall I commit that? It s quite simple.
diff --git a/src/org/metawatch/manager/weather/GoogleWeatherEngine.java b/src/org/metawatch/manager/weather/GoogleWeatherEngine.java
index d3d786d..57f135f 100644
--- a/src/org/metawatch/manager/weather/GoogleWeatherEngine.java
+++ b/src/org/metawatch/manager/weather/GoogleWeatherEngine.java
@@ -76,6 +76,10 @@
+ Preferences.weatherCity;
weatherData.locationName = Preferences.weatherCity;
}
+
+ // Fixed #46 (Google Weather failing when using manually input location)
+ // The URL must not contain spaces. We need to replace them.
+ queryString = queryString.replace(" ", "%20");
HttpClient hc = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(queryString);
Yup, that's fine - it's basically what the Wunderground code is/was doing
I'm currently getting an issue with the Google Weather provider
It's failing at GoogleWeatherEngine.java:81
Location set to "Cambridge, UK"
IllegalArgumentException: Illegal character in query at index 47: http://www.google.com/ig/api?weather=Cambridge, UK (which appears to be the comma)
So I manually url encoded the string instead ("Cambridge%2C%20UK")
This now gives IllegalArgumentException: Illegal character in query at index 54: http://www.google.com/ig/api?weather=Cambridge%2C%20UK
(which is the end of the string)