我会尽量更精确。我试图打开一个从自定义按钮附加到标记的“infowindow”。虽然它通过直接单击标记工作,但我没有将它分配给按钮。该页面目前看起来像这样: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);
});
谢谢。
答案 0 :(得分: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"
});
...