接之前所写关于百度地图API所提供的显示地理位置信息的功能,我们也可以加入显示天气预报的API,从而使用户可以通过自己的网页看到天气预报。
以下为笔者所写的一份简单测试代码。
首先连接百度地图API。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script src="http://api.map.baidu.com/components?ak=ImEwcIPvf92bBwvxhXYENARr&v=1.0"></script>
其次使用显示天气预报的元素。lbs-weather中,笔者同样将city属性默认为广州。
<title>天气预报</title>
<style type="text/css">
body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;}
@media (max-device-width: 800px){#golist{display: block!important;}}
</style>
</head>
<body>
<lbs-weather city="广州"></lbs-weather>
<a id="golist" href="/">返回主页</a>
</body>
</html>
如下为测试网页