摘要:google map V3 infowindow的蠢問題
目的要在新增的標記上都能順利跑出infowindow,後來發現它的content:"zzzzzzzzz"屬性是必要(?)參數,否則都沒用...
//初始化地圖
function initialize() {
var haightAshbury = new google.maps.LatLng(37.7699298, -122.4469157);
var mapOptions = {
zoom: 12,
center: haightAshbury,
mapTypeId: google.maps.MapTypeId.TERRAIN
};
map = new google.maps.Map(document.getElementById("map_canvas"),
mapOptions);
//畫線屬性
var polyOptions = {
clickable:true,
map:map,
strokeColor: '#000000',
strokeOpacity: 1.0,
strokeWeight: 3
}
//new Polyline(帶入上面屬性)
poly = new google.maps.Polyline(polyOptions);
//按鍵事件
google.maps.event.addListener(map, 'click', function(event) {
addPoint(event.latLng); });
}
//增加標記的函數
function addPoint(location) {
var path=poly.getPath(); //沒寫在事件呼叫的函數裡好像沒作用,關網
//畫線專用的陣列.getPath()
path.push(location); //不是很懂這一段,只知push
marker[i] = new google.maps.Marker({ //new 標記+屬性給一給
position: location,
title:"--"+i,
map: map
});
//new 訊息框,content是必要屬性 幹,沒給內容就什麼都沒有
infowindow=new google.maps.InfoWindow ({content: "contentString"});
infowindow.open(map,marker[i]); //紀錄指定標記和訊息窗的mach
markersArray.push(marker); //擴充標記陣列(我多用一個"i"去記)
i++;
}