刚刚试用了一下,有两点注意:
1.要加载缩略图,标尺控件位置需注意 放在 map.centerAndZoom(point,15);后面,否则 this.centerPoint 为null。
2. 要使用服务API,注意 &services=true。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gbk" /> <title>Hello, World</title> <script src="http://api.map.baidu.com/api?key=46ce9d0614bf7aefe0ba562f8cf87194&v=1.0&services=true" type="text/javascript"></script> </head> <body> <div style="width:520px;height:340px;border:1px solid gray" id="container"></div> </body> </html> <script type="text/javascript"> var map = new BMap.Map("container"); // 创建Map实例 var point = new BMap.Point(116.404, 39.915); // 创建点坐标 map.centerAndZoom(point,15); // 初始化地图,设置中心点坐标和地图级别。 map.addControl(new BMap.NavigationControl()); //导航 map.addControl(new BMap.OverviewMapControl()); //缩略 map.addControl(new BMap.ScaleControl()); //标尺 // 创建地址解析器实例 var myGeo = new BMap.Geocoder(); // 将地址解析结果显示在地图上,并调整地图视野 myGeo.getPoint("杭州市滨江信诚路555", function(point){ if (point) { map.centerAndZoom(point, 16); var marker = new BMap.Marker(point); marker.addEventListener("click",function(){ marker.openInfoWindow(new BMap.InfoWindow("hello world")); }); marker.setLabel(new BMap.Label("lexinquan",{offset:new BMap.Size(10,-40)})); map.addOverlay(marker); } }, "杭州市"); //var city = new BMap.LocalCity(); //city.get(function(result){ // alert(result.name); // }); </script>