Hi all,
I found a lot of threads about placing a weather icon in maps (or create a sensor to monitor it) but nothing worked well for me so I did one by myself.
Admin Note:
Requires an secondary web-server capable of processing php scripts.
1. Create a page called weather.php and copy/paste this:
<? $request = 'http://api.openweathermap.org/data/2.5/weather?q='. $_GET["location"] .'&lang=en'; $response = file_get_contents($request); $jsonobj = json_decode($response); ?> <div style="border: 1px solid black; width: 85px; text-align: center;"> <p style="margin: 0px; font-family: Verdana; font-size: 10px"><?echo $jsonobj->{'weather'}[0]->{'description'}?></p> <img src="http://openweathermap.org/img/w/<?echo $jsonobj->{'weather'}[0]->{'icon'}?>.png"> </div>
Save weather.php on your web server.
2. Add in your map a custom HTML object and copy this code in the html-after:
<iframe src="http://yourwebserver/weather.php?location=London,uk" allowtransparency="true" frameborder="0"></iframe>
I hope that this could help you :)
Article Comments
If someone's getting an error with the file_get_content you could use this code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://api.openweathermap.org/data/2.5/weather?q='. $_GET["location"] .'&lang=it&units=metric&APPID=XXXXXXXXXXXXXXXXXX');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HEADER, false);
$response = curl_exec($ch);
curl_close($ch);
instead of this one:
$request = 'http://api.openweathermap.org/data/2.5/weather?q='. $_GET["location"] .'&lang=en';
$response = file_get_contents($request);
You've to replace the XXXXXXXXXXXXXXXXXX string with the appid that you receive once you register a username in the openweather site .
Oct, 2015 - Permalink
Greetings AndreaM,
we appreciate your contribution. Thank you.
Best Regards,
Aug, 2015 - Permalink