Weather underground + geolocation.js fallback
based on http://jsfiddle.net/junwatu/kvPA2/ Simple weather app with html, css, and js!. This app using Weather API from Weather Underground and HTML5 Geolocation API!.
by lovromar
HTML
<script src="http://www.modernizr.com/downloads/modernizr-latest.js"></script>
<h1><span class="location"></span> ,<span class="country"></span></h1>
<div class="header today">
<p id="when"></p>
<p id="condition"></p>
<img id="weather_icon"/>
<p id="temp"></p>
</div>
<div class="header tomorrow">
<p id="when"></p>
<p id="condition"></p>
<img id="weather_icon"/>
<p id="temp"></p>
</div>
<div class="header after_tomorrow">
<p id="when"></p>
<p id="condition"></p>
<img id="weather_icon"/>
<p id="temp"></p>
</div>
CSS
.header {
padding: 5px 5px;
outline:solid 1px #cacaca;
}
#content {
width:280px;
padding : 5px 5px;
}
#content p {
float: right;
}
#temp {
font-size:25px;
}
JavaScript
/**
* This app using Weather API from http://www.wunderground.com
* and HTML5 Geolocation API
*
* Note:
* Change wu_api_key to your own wunderground.com api key!.
* This app tested on Google Chrome 14 Linux and Firefox 7 Linux.
*
* Cuakaku function Author Equan Pr.
* http://www.junwatu.com
*
* Modified Mikeldi Cesteros and added geolocation.js script found at alvinmoon
*/
/* http://alvinwoon.com/source/javascript%20geolocation%20api/ */
var GEO_LOCATION={watchID:null,callback:null};GEO_LOCATION.mySpot=function(position){var lat=(position.coords)?new String(position.coords.latitude):position.x;var lon=(position.coords)?new String(position.coords.longitude):position.y;return GEO_LOCATION.callback(lat,lon);}
GEO_LOCATION.getLocation=function(func,timeout){GEO_LOCATION.callback=func;if(navigator.geolocation){this.requestCurrentPosition(this.mySpot,this.errorCallback,this.timeoutCallback,timeout,{maximumAge:10000,timeout:timeout,enableHighAccuracy:true});}else{alert('Geolocation feature is not available. Trying to locate your location using alternate methods...');setTimeout(this.errorCallback,3000);}}
GEO_LOCATION.requestCurrentPosition=function(successCB,errorCB,timeoutCB,timeoutThreshold,options){var successHandler=successCB;var errorHandler=errorCB;window.geolocationTimeoutHandler=function(){timeoutCB();}
if(typeof(geolocationRequestTimeoutHandler)!='undefined'){clearTimeout(window['geolocationRequestTimeoutHandler']);}
var timeout=timeoutThreshold||30000;window['geolocationRequestTimeoutHandler']=setTimeout('geolocationTimeoutHandler()',timeout);GEO_LOCATION.watchID=navigator.geolocation.watchPosition(function(position){successHandler(position);clearTimeout(window['geolocationRequestTimeoutHandler']);},function(error){if(!GEO_LOCATION.room){clearTimeout(window['geolocationRequestTimeoutHandler']);alert("Something went wrong. Trying to locate your position using your IP address instead. Please...