2011-08-30 52 views
1

我想用Google maps V3構建多邊形,但是我遇到了這個問題:當我將自己的代碼放入初始化函數中時,它可以工作......但是當我將它外化時,它不起作用。從Javascript初始化函數不起作用?

這是我的代碼:

function AddSecteurs() { 
    var Secteur ; 
    var SecteurCoords = [ 
      new google.maps.LatLng(47.216770, -1.553879), 
      new google.maps.LatLng(47.516770, -1.563879), 
      new google.maps.LatLng(47.216770, -1.574579), 
      new google.maps.LatLng(47.216770, -1.5744179), 
      new google.maps.LatLng(47.216770, -1.584579), 
      new google.maps.LatLng(47.236770, -1.574579), 
      new google.maps.LatLng(47.229770, -1.574579)]; 
    Secteur = new google.maps.Polygon({ 
     paths: SecteurCoords, 
     strokeColor: "#FF0000", 
     strokeOpacity: 0.8, 
     strokeWeight: 2, 
     fillColor: "#FF0000", 
     fillOpacity: 0.35, 
    }); 
    Secteur.setMap(map); 
} 
+0

即在該功能的一部分。 – Gwenael

+0

實際上,這個函數得到了我剛剛外化的代碼,這段代碼在我文件的Initiliaze函數中 – Gwenael

回答

0

看來你錯過了你的功能map變量。

就宣佈它作爲一個參數:

function AddSecteurs(map) ... 

它從Initialize功能傳遞給新功能:

AddSecteur(map);