我已经添加了weatherwidget-io天气应用程序到我的网站,我想添加地理位置,而不是有一个固定的位置。因此,任何访问我网站的用户都会看到他们所在位置的天气。
HTML和JS代码:
<a class="weatherwidget-io" href="https://forecast7.com/en/55d95n3d19/edinburgh/" data-label_1="EDINBURGH" data-label_2="WEATHER" data-theme="original">EDINBURGH WEATHER</a>
</div>
<script>
!function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (!d.getElementById(id)) {
js = d.createElement(s);
js.id = id;
js.src = 'https://weatherwidget.io/js/widget.min.js';
fjs.parentNode.insertBefore(js, fjs);
}
}(document, 'script', 'weatherwidget-io-js');
</script>发布于 2019-09-30 22:46:21
一种方法是使用Geolocation API来请求用户的位置。您可以从中获得用户的纬度和经度坐标。然后,您可以使用Reverse Geocoding来获取该特定坐标的城市。然后,您可以使用这些信息从weatherwidget-io天气应用程序中请求城市的天气。
https://stackoverflow.com/questions/58170027
复制相似问题