// 初始化地图
var map = new BMap.Map("map-container");
// 设置缩放级别
map.setZoom(16);
// 添加地图控件
var navigationControl = new BMap.NavigationControl();
map.addControl(navigationControl);
// 添加标注
var point = new BMap.Point(116.404, 39.915);
var marker = new BMap.Marker(point);
map.addOverlay(marker);
简单样例下面是一个简单的Web页面,演示了如何使用<bmap.css来创建并显示地图:
<html>
<head>
<link rel="stylesheet" type="text/css" href="bmap.css">
</head>
<body>
<div id="map-container"></div>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=<your-key-here>&callback=initMap"></script>
<script type="text/javascript">
function initMap() {
var map = new BMap.Map("map-container");
map.centerAndZoom(new BMap.Point(116.404, 39.915), 14);
map.addControl(new BMap.NavigationControl());
map.addControl(new BMap.ScaleControl());
map.addControl(new BMap.OverviewMapControl());
map.addControl(new BMap.MapTypeControl());
var marker = new BMap.Marker(new BMap.Point(116.404, 39.915));
map.addOverlay(marker);
}
</script>
</body>
</html>