嘿嗬=)simpleWeather和moment.js - 無效的日期與JS-地理位置德國
我想創造一個天氣插件,我的網站。所以我選擇了simpleWeather插件。
的simpleWeather插件使用的moment.js LIB得到最後更新的時間。但插件本身不提供語言選項。
我的標準位置是「德國基爾」。
但它不工作,並說「無效的日期」。 我不知道,爲什麼!
有人可以幫我嗎?
/* Does your browser support geolocation? */
if ("geolocation" in navigator) {
$('.js-geolocation').show();
} else {
$('.js-geolocation').hide();
}
/* Where in the world are you? */
$('.js-geolocation').on('click', function() {
navigator.geolocation.getCurrentPosition(function(position) {
getWeather(position.coords.latitude+','+position.coords.longitude); //load weather using your lat/lng coordinates
});
});
$(document).ready(function() {
getWeather('Kiel',''); //@params location, woeid //Get the initial weather.
});
function getWeather(location, woeid) {
$.simpleWeather({
//20065908 KIEL woeid
location: location,
woeid: woeid,
unit: 'c',
success: function(weather) {
html = '<ul>Today: <i class="icon-'+weather.code+'"></i><br />';
html += '<li>'+weather.temp+'°'+weather.units.temp+'</li>';
html += '<li>'+weather.city+', '+weather.region+'</li></ul>';
//Don't forget to include the moment.js plugin.
var timestamp = moment(weather.updated);
html += '<p>Weather updated '+moment(timestamp).fromNow()+'</p>';
html += '<p>Weather updated at '+moment(timestamp).format('MM/DD/YY h:mma')+'</p>';
for(var i=0;i<weather.forecast.length;i++) {
html += ''+weather.forecast[i].day+': <i class="icon-'+weather.forecast[i].code+ '"></i>';
}
$("#weather").html(html);
},
error: function(error) {
$("#weather").html('<p>'+error+'</p>');
}
});
}
不知地理位置究竟是如何工作的......但我認爲moment.js使用地理定位來設置語言。 於是,我就設置moment.js globaly區域設置成「en」,但它也沒有工作,我沒有料到。
謝謝,詳細的答案!這工作完美! –