<!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>Hello, World</title>
<style type="text/css">
html{height:100%}
body{height:100%;margin:1px;padding:0px}
#container{height:90%; 90%;}
#r-result{100%;}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=nuREme2f3oRuk2B94maVieQHUhgUaC2E">
//v2.0版本的引用方式:src="http://api.map.baidu.com/api?v=2.0&ak=您的密钥"
//v1.4版本及以前版本的引用方式:src="http://api.map.baidu.com/api?v=1.4&key=您的密钥&callback=initialize"
</script>
</head>
<span id='p1'>广州</span> <span id='p2'>深圳</span> <span id='p3'>上海</span>
<body>
<div id="container"></div>
<div id="r-result"></div>
<script type="text/javascript">
var map = new BMap.Map("container"); // 创建地图实例
var point = new BMap.Point(116.404, 39.915); // 创建点坐标
var p1 = document.getElementById('p1');
p1.onclick = function () {
point = new BMap.Point(113.124253,23.305379);
var marker = new BMap.Marker(point); // 创建标注
map.addOverlay(marker);
marker.onclick=function (){
var label = new BMap.Label("广州",{offset:new BMap.Size(20,-10)});//标注添加注释
marker.setLabel(label);
}
}
map.centerAndZoom(point, 4); // 初始化地图,设置中心点坐标和地图级别
// map.addControl(new BMap.NavigationControl()); //添加缩放标尺
map.enableScrollWheelZoom();//鼠标滚轮缩放地图
var size = new BMap.Size(70, 20);
map.addControl(new BMap.CityListControl({
anchor: BMAP_ANCHOR_TOP_LEFT,
offset: size,
// 切换城市之间事件
// onChangeBefore: function(){
// alert('before');
// },
// 切换城市之后事件
// onChangeAfter:function(){
// alert('after');
// }
}));
</script>
</body>
</html>