0

我用這個例子來借鑑谷歌地圖的多邊形:谷歌地圖接收多邊形座標

http://nettique.free.fr/gmap/toolbar.html

繪製多邊形之後,我想讀我創建多邊形的座標。因此,在文件mapToolbar.js(這是來自nettique.free.fr的上述示例的一部分)在javascript函數中調用stopediting(當我點擊'hand'按鈕時運行)。

所以,我的解決方案來讀取這些座標是somekind的循環,我讀的座標:

MapToolbar.features.shapeTab.shape_1.latLngs.b[0].b[i].ib - latitude 

MapToolbar.features.shapeTab.shape_1.latLngs.b[0].b[i].jb - longitude 

它工作的很好,但我的問題是,不時後綴ibjb變更爲實例YaZa。我希望你知道這意味着什麼。我必須改變我的代碼;但我不想! ;)

你知道如何解決這個問題嗎?

回答

2

MapToolbar.features.shapeTab.shape_1是一個google.maps.Polygon -instance。

使用getPath()檢索路徑,並在路徑的方法forEach循環:

MapToolbar.features.shapeTab.shape_1.getPath().forEach(function(latLng,index){ 
    console.log('shape_1',index,latLng.toString()); 
    }); 
+0

非常感謝您!你保存了我的迷你項目;) – 2013-03-09 21:48:44