各个城市地图的轮廓线_javascript


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=sSelQoVi2L3KofLo1HOobonW"></script>
<title>获取地区轮廓线</title>
</head>
<body>
<div id="map" style="width:100%;height:500px"></div>
<script type="text/javascript">
var map = new BMap.Map("map");
map.enableScrollWheelZoom();
function getBoundary()
{
var bdary = new BMap.Boundary();
var name = '昆山'; //**在这里直接输入城市名字即可**
bdary.get(name, function(rs){ //获取行政区域
map.clearOverlays(); //清除地图覆盖物
var count = rs.boundaries.length; //行政区域的点有多少个
for(var i = 0; i < count; i++){
var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 2, strokeColor: "#ff0000"}); //建立多边形覆盖物
map.addOverlay(ply); //添加覆盖物
map.setViewport(ply.getPath()); //调整视野
}
});
}
getBoundary();
</script>
</body>
</html>

在 var name = ‘昆山’; 这里的昆山可以换成任何城市,亲测有效,比如北京啦,上海啦,等等