Open OpenWeatherMap API in matlab

12 ビュー (過去 30 日間)
Dion Theunissen
Dion Theunissen 2021 年 7 月 22 日
コメント済み: Yongjian Feng 2021 年 7 月 24 日
I just need to know the weather at a current position.
I have the following script, but it doesn't work.
key = 'MyKey';
op = 'TA2';
z = '1';
x = '51.36';
y = '6.16';
options = weboptions('ContentType','json');
url = ['',z,'/',x,'/',y,'?date=1527811200&opacity=0.9&fill_bound=true&appid=',key];
Current_Data = webread(url, options);
Can anyone tell me what is going wrong here? I got the folowing URL from OpenWeatherMap:{op}/{z}/{x}/{y}?appid={API key}
Thanks in advance

回答 (1 件)

Yongjian Feng
Yongjian Feng 2021 年 7 月 22 日
What does it mean by "it doesn't work"? Any error message you saw?
Try the html directly outside matlab and make sure it works first. You can use curl from command line window.
  3 件のコメント
Yongjian Feng
Yongjian Feng 2021 年 7 月 24 日
@Dion Theunissen: When you run webread(url) from matlab command line, what error does it shown on the command line window? I tried your example, it shows HTTP status 401, which means unauthorized. This is correct because I don't have an API key. But your url looks good.





Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by