0

我会尝试更精确。我正在尝试从自定义按钮打开一个附加到标记的“信息窗口”。虽然它通过直接单击标记来工作,但我无法将其分配给按钮。该页面当前如下所示:map_example

谁能检查下面的代码并告诉我我做错了什么?

function zagrebControl(controlDiv, map) {
controlDiv.style.paddingLeft = '0px';
controlDiv.style.paddingRight = '6px';
controlDiv.style.paddingTop = '0px';
controlDiv.style.paddingBottom = '6px';
controlDiv.style.marginBottom = '0px';
controlDiv.style.width = '80px';

var zagrebUI = document.createElement('DIV');
zagrebUI.style.backgroundColor = 'white';
zagrebUI.style.borderStyle = 'solid';
zagrebUI.style.borderWidth = '1px';
zagrebUI.style.cursor = 'pointer';
zagrebUI.style.textAlign = 'center';
zagrebUI.title = 'click to set the map to zagreb';
controlDiv.appendChild(zagrebUI);

var controlText = document.createElement('DIV');
controlText.style.fontFamily = 'Arial,sans-serif';
controlText.style.fontSize = '12px';
controlText.style.paddingLeft = '4px';
controlText.style.paddingRight = '4px';
controlText.style.paddingTop = '1px';
controlText.style.paddingBottom = '0px';
controlText.innerHTML = 'ZAGREB';
zagrebUI.appendChild(controlText);

google.maps.event.addDomListener(zagrebUI, 'click', function() {
map.setCenter(v1); map.setZoom(7)
});
google.maps.event.addListener(zagrebUI, 'click', function() {
infowindow.setContent('<object width="640" height="360">...</object>');
infowindow.open(map, m1)
});

我的标记代码如下所示:

google.maps.event.addListener(m1, 'click', function() {
infowindow.setContent('<object width="640" height="360">...</object>');
infowindow.open(map, m1);

});

谢谢你。

4

1 回答 1

0

m1不是全局变量,所以infowindow.open(map, m1)浏览器不知道m1

m1全局声明。

var m1;
function initialize() {
...
m1 = new google.maps.Marker({
  position: new google.maps.LatLng(45.81871335, 15.97911),
  map: map,
  animation: google.maps.Animation.DROP,
  title: "ZAGREB"
});
...
于 2012-02-17T08:49:39.217 回答