在网页中插入
百度地图,样式代码如下
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Baidu Map </title>
</head>
<body>
<style type="text/css">
.mapwarp{
width: 80%;
height: 200px;
margin: 0 auto;
}
#baidumap {
height: 100%
}
</style>
<script type="text/javascript" src="//api.map.baidu.com/api?type=webgl&v=1.0&ak=1V4mSproiau7AxsArSNKBWqR0ZiyMKNh&s=1"></script>
<div class="mapwarp">
<div id="baidumap" class="mapwarp"></div>
</div>
<script>
var map = new BMapGL.Map('baidumap');
var point = new BMapGL.Point(116.404, 39.925);
map.centerAndZoom(point, 15);// 创建点标记
var marker = new BMapGL.Marker(point);
map.addOverlay(marker);// 创建信息窗口
var opts = {
width: 200,
height: 100,
title: '故宫博物院'
};
var infoWindow = new BMapGL.InfoWindow('地址:北京市东城区王府井大街88号乐天银泰百货八层', opts);// 点标记添加点击事件
marker.addEventListener('click', function () {
map.openInfoWindow(infoWindow, point); // 开启信息窗口
});
map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
</script>
</body>
</html>