我正在使用HTML5地理位置api获取用户的位置,如下所示:
navigator.geolocation.getCurrentPosition(function (position) {
loadWeather(position.coords.latitude + ',' + position.coords.longitude); //load weather using your lat/lng coordinates
});
jQuery(document).ready(function() {
loadWeather('Seattle',''); //@params location, woeid
});
function loadWeather(location, woeid) {
jQuery.simpleWeather({
location: location,
woeid: woeid,
unit: 'c',
success: function(weather) {
html = '<div class="weather_widget text-right"><h2><div class="icon_weather"><i class="icon-'+weather.code+'"></i></div><div class="degrees"><div class="temp_weather">'+weather.temp+'</div><div class="weather_deg">°</div><div class="unit_weather">'+weather.units.temp+'</div></div></h2>';
html += '<div class="city_weather">'+weather.city+'</div></div>';
jQuery("#weather").html(html);
},
error: function(error) {
jQuery("#weather").html('<p>'+error+'</p>');
}
});
}
基本上,这会加载一个小部件,该小部件根据地理位置定位显示天气。
现在我的问题是:
如何存储整个会话的位置变量?(以便每次加载新页面时都不会询问位置吗?)
如何使位置变量可供整个网站访问,以便可以在网站的其他功能中使用该位置?(例如谷歌地图)。
地理位置代码位于站点中包含的头文件中。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句