將下面程式碼複製到記事本,另存為HTML檔案,用瀏覽器開啟,輸入你要獲取的地區名稱點選‘獲取輪廓線’,只能獲取 省 市 縣 的輪廓,暫時還沒有鄉鎮和村的。<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script><title>獲取地區輪廓線</title></head><body><div></div><input type="text" onFocus="this.select()"/><input type="button" onclick="getBoundary()" value="獲取輪廓線"/><textarea></textarea><script type="text/javascript">var map = new BMap.Map("container");map.centerAndZoom(new BMap.Point(116.403765, 39.914850), 5);map.addControl(new BMap.NavigationControl({type: BMAP_NAVIGATION_CONTROL_SMALL}));map.enableScrollWheelZoom();function getBoundary(){var bdary = new BMap.Boundary();var name = document.getElementById("districtName").value;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()); //調整視野}document.getElementById("Div1").innerText = rs.boundaries;//"{"type":"Feature","id":"0","properties":{"name":""+name+""},"geometry":{"type":"Polygon","coordinates":[[[" + String().replace(";","],[") + "]]}}";});}</script></body></html
將下面程式碼複製到記事本,另存為HTML檔案,用瀏覽器開啟,輸入你要獲取的地區名稱點選‘獲取輪廓線’,只能獲取 省 市 縣 的輪廓,暫時還沒有鄉鎮和村的。<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script><title>獲取地區輪廓線</title></head><body><div></div><input type="text" onFocus="this.select()"/><input type="button" onclick="getBoundary()" value="獲取輪廓線"/><textarea></textarea><script type="text/javascript">var map = new BMap.Map("container");map.centerAndZoom(new BMap.Point(116.403765, 39.914850), 5);map.addControl(new BMap.NavigationControl({type: BMAP_NAVIGATION_CONTROL_SMALL}));map.enableScrollWheelZoom();function getBoundary(){var bdary = new BMap.Boundary();var name = document.getElementById("districtName").value;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()); //調整視野}document.getElementById("Div1").innerText = rs.boundaries;//"{"type":"Feature","id":"0","properties":{"name":""+name+""},"geometry":{"type":"Polygon","coordinates":[[[" + String().replace(";","],[") + "]]}}";});}</script></body></html