【发布时间】:2014-08-14 03:44:53
【问题描述】:
嗨,我有一个来自simpleweatherjs 的工作天气脚本,我觉得这很奇怪,因为从我发现的示例中,一切都在差异浏览器上运行,但是当我通过结合自动更新和地理定位并在我们的同事的帮助下自定义插件时在堆栈中,我设法使其运行,但仅在 chrome 上运行,因为当我在 Firefox 上对其进行测试时,它只会在我允许它没有发生任何事情后询问我是否要共享位置
这是完整的代码
<script type="text/javascript">
$(document).ready(function() {
getWeather();
setInterval(getWeather, 6000);
});
function getWeather() {
navigator.geolocation.getCurrentPosition(function(position) {
var location = (position.coords.latitude + ',' + position.coords.longitude);
var woeid = undefined;
$.simpleWeather({
location: location,
woeid: woeid,
unit: 'c',
success: function(weather) {
html = '<h2><i class="icon-'+weather.code+'"></i>' + weather.temp + '°' + weather.units.temp + '</h2>';
html += '<ul><li>' + weather.city + ', ' + weather.region + '</li>';
html += '<li class="currently">' + weather.currently + '</li></ul>';
$("#weather").html(html);
},
error: function(error) {
$("#weather").html('<p>' + error + '</p>');
}
});
});
}
</script>
谁能告诉我这里哪里出错了?
【问题讨论】:
标签: javascript jquery firefox weather-api