File Exchange

image thumbnail

Google Weather

version 1.6 (2.45 KB) by

Get location specific weather data using Google's Weather API



View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

Google Weather
Get location specific weather data using Google's Weather API

1. gweather()
2. gweather('place') Ex. gweather('Goa')
3. gweather(lat,long) Ex. gweather(15.563,73.818)
(lat,long in decimal degrees)

Besides printing the current conditions and the forecast, the function
returns the forecast information in a structure. (Output)

Sample Output:

Current Conditions:
3°C, 86% Humidity, Light rain

Thu: -7°C to 3°C, Icy
Fri: 0°C to 2°C, Mostly Sunny
Sat: 0°C to 10°C, Rain
Sun: -6°C to 6°C, Cloudy

Apparently, the Google Weather XML Feed is not officially supported.
Use of lat,long often provides unreliable results.

Comments and Ratings (6)


Ikko (view profile)

Google weather API has closed, and there is no URL any more, which is why we have an error.

kyana shayan

it doesn't work for me.
i got this message
Error using urlreadwrite (line 90)
The server did not find a resource to match this request.

Error in urlread (line 36)
[s,status] = urlreadwrite(mfilename,catchErrors,url,varargin{:});

Error in gweather (line 64)
data = urlread(url);
can anyone help me?

Sagar Aiya

Thanks Yuri Kotliarov and R for your suggestion about clc.

Thanks a lot Andrew Bliss!
That flaw went unnoticed for quite some time. One of the reasons being that low temperatures (forecasts) were retrieved in deg F and later converted into deg Celsius before printing. That way, I could get temperatures as low as 0 deg F (-17.78 deg C) but not any lower.

I've made necessary changes and will upload the file soon.

Andrew Bliss

Andrew Bliss (view profile)

A nice function. Parsing is generally good, but failed for negative temperatures when I ran it. To fix:

For CURRENT_CONDITIONS and FORECASTS change [\w\s\d_/<>=%":.]* to .*

For TEMP, LOWS, and HIGHS change [\d] to [-\d]

Also, not everyone will want an output structure. Get around that with:
function outputstruct = gweather...
...%(your whole function)
if nargout
outputstruct = Output;


R (view profile)

I agree clc is bad practice for a function to be distributed, otherwise great job

Yuri K

Yuri K (view profile)

Cool! But clc is not a good practice in function.



- clc has been removed.
- Fixed the issue of negative temperatures as suggested by Andrew Bliss.


Uploaded the updated gweather.m file which I forgot to upload during the previous update.


provision to supply geographical coordinates as arguments instead of a location name.

MATLAB Release
MATLAB 7.10 (R2010a)
Tags Add Tags

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today