我怎麼能當使用信息框插件http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/examples/infobox-basic.html谷歌地圖API的信息框插件和多指標
我創建VAR MARKER1,VAR MARKER2等創建具有不同內容的多個標誌,但我認爲這並不是非常好的方法,我有在所有的信息窗口相同內容...
我怎麼能當使用信息框插件http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/examples/infobox-basic.html谷歌地圖API的信息框插件和多指標
我創建VAR MARKER1,VAR MARKER2等創建具有不同內容的多個標誌,但我認爲這並不是非常好的方法,我有在所有的信息窗口相同內容...
你只需要一個工廠某種生成的標記,如:
function initMarkers(map, markerData) {
var newMarkers = []
// Here's where all the really verbose code goes. Loop through `markerData` to
// create each marker. See the full code in the js fiddle
return newMarkers;
}
function initialize_google_map() {
//Here the call to initMarkers() is made with the necessary data for each marker.
//All markers are then returned as an array into the markers variable, Usually you'd
//get the data from server or something, here it's just shown inline.
var markers = initMarkers(map, [
{ latLng: new google.maps.LatLng(49.47216, -123.76307), address: "Address 1", state: "State 1" },
{ latLng: new google.maps.LatLng(49.47420, -123.75703), address: "Address 2", state: "State 2" },
{ latLng: new google.maps.LatLng(49.47530, -123.78040), address: "Address 3", state: "State 3" }
]);
}
退房HTML和完整的例子諸如此類in this jsfiddle。
對於信息框切換的onclick取代:
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
newMarkers[i].infobox.open(theMap, this);
theMap.panTo(markerData[i].latLng);
}
})(marker, i));
通過:
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
for (h = 0; h < newMarkers.length; h++) {
newMarkers[h].infobox.close();
}
newMarkers[i].infobox.open(theMap, this);
theMap.panTo(markerData[i].latLng);
}
})(marker, i));
@DonamiteIsTnt你的例子是真正有用的,但markerData [我]沒有任何財產的latLng我請使用markerData [i] .position。它爲我工作。