[Google Map]畫多邊形(GPolygon)
八月 10, 2008
除了點(GMark)線(GPolyline)之後,我們還能表現面(GPolygon)!
Google API
- GPolygon : This is very similar to a GPolyline, except that you can additionally specify a fill color and opacity.
- 位置陣列中一定要封閉,即第一點和最後一點的座標要相同。
程式碼
google.load("maps", "2.x");
google.setOnLoadCallback(initialize);
var map = null;
function initialize() {
// 檢查瀏覽器是否可使用 Google Map API
if ( GBrowserIsCompatible() ) {
map = new google.maps.Map2(document.getElementById('map'));
// 設定地圖中心點
map.setCenter(new GLatLng(25.036772,121.520269), 11);
var points = [];
points.push(new GLatLng(25.030000,121.490556)); // 萬華
points.push(new GLatLng(25.035556,121.424722)); // 新莊
points.push(new GLatLng(25.063611,121.518056)); // 中山
points.push(new GLatLng(24.978889,121.529167)); // 新店
points.push(new GLatLng(25.013611,121.466667)); // 板橋
points.push(new GLatLng(25.030000,121.490556)); // 萬華(封閉)
// 畫多邊形
map.addOverlay(new GPolygon(points,'#FF0000',3,0.5,'#ffff00',0.5));
} // if
else {
alert('您的瀏覽器不支援Google Map');
} // else
}