2

我知道这个问题有很多答案。我已经测试了所有,但它们不适用于我的代码。当我在脚本中使用代码时,它停止工作。

 

function createMarker(latlng) {
    var marker = new google.maps.Marker({
        position: latlng,
        map: map,
        icon:'images/intake.png',   
        html:(contentString,contentString1,contentStringPhoto)
    });

    infoBubble = new InfoBubble({
      maxWidth: 400
    });
    var div = document.createElement('DIV');
    div.innerHTML = 'NN-Gis';

    infoBubble.addTab('Information', contentString);
    infoBubble.addTab('Information', contentString1);
    infoBubble.addTab('Photo', contentStringPhoto);


    google.maps.event.addListener(marker, 'click', function() {
      if (!infoBubble.isOpen()) {

          infoBubble.setContent(contentString,contentString1,contentStringPhoto);

          infoBubble.open(map,marker);
      }
    });

  }
  google.maps.event.addDomListener(window, 'load', init);

  function updateStyles() {
    var shadowStyle = document.getElementById('shadowstyle').value;
    infoBubble.setShadowStyle(shadowStyle);

    var padding = document.getElementById('padding').value;
    infoBubble.setPadding(padding);

    var borderRadius = document.getElementById('borderRadius').value;
    infoBubble.setBorderRadius(borderRadius);

    var borderWidth = document.getElementById('borderWidth').value;
    infoBubble.setBorderWidth(borderWidth);

    var borderColor = document.getElementById('borderColor').value;
    infoBubble.setBorderColor(borderColor);

    var backgroundColor = document.getElementById('backgroundColor').value;
    infoBubble.setBackgroundColor(backgroundColor);

    var maxWidth = document.getElementById('maxWidth').value;
    infoBubble.setMaxWidth(maxWidth);

    var maxHeight = document.getElementById('maxHeight').value;
    infoBubble.setMaxHeight(maxHeight);

    var minWidth = document.getElementById('minWidth').value;
    infoBubble.setMinWidth(minWidth);

    var minHeight = document.getElementById('minHeight').value;
    infoBubble.setMinHeight(minHeight);

    var arrowSize = document.getElementById('arrowSize').value;
    infoBubble.setArrowSize(arrowSize);

    var arrowPosition = document.getElementById('arrowPosition').value;
    infoBubble.setArrowPosition(arrowPosition);

    var arrowStyle = document.getElementById('arrowStyle').value;
    infoBubble.setArrowStyle(arrowStyle);
  }
4

1 回答 1

0

我相信您会收到此错误,因为变量contentString,等在被调用contentString1时超出范围或未定义。createMarker

确保在调用函数之前定义了这些createMarker,例如

var contentString="abc";
var contentString1="abcdef";
var contentStringPhoto="abcfegggg";

或者,将这些变量作为参数添加到您的函数中。定义:

function createMarker(latlng,contentString,contentString1,contentStringPhoto) {

于 2012-10-16T19:47:06.203 回答