当我点击谷歌地图标记时,新的信息窗口不起作用

时间:2014-09-15 12:26:58

标签: google-maps-api-3 google-maps-markers

你好我点击标记时显示新的infowindow有问题。我想点击标记后显示infowindow。请有人给我一个解决方案。我的代码如下。

var markerClusterer = null;

var map = null;

function refreshMap() {

    if (markerClusterer) {
      markerClusterer.clearMarkers();
    }

    var markers = [];
     var style = parseInt(document.getElementById('style').value, 10);      
    if (style == 0) {           
        var data =w_plaza;
        var imageUrl = 'images/walton.png';
    }
    if (style == 1) {           
        var data =w_dealer;
        var imageUrl = 'images/people35.png';
    }
    if (style == 2) {           
        var data =w_service_center;
        var imageUrl = 'images/service_center.png';
    }

    var markerImage = new google.maps.MarkerImage(imageUrl);
      //  var markerImage = new google.maps.MarkerImage(imageUrl,
      //new google.maps.Size(24, 32));



      for (var i = 0; i < data.length; i++) {
      var loc = data[i];
      var latLng =  new google.maps.LatLng(loc[1],loc[2]);
      var content = loc[0] + ":" + loc[1] + "," + loc[2];          
      var marker = new google.maps.Marker({
       position: latLng,
       draggable: true,
       icon: markerImage
      });   

      google.maps.event.addListener(marker, 'click', function() {
      infowindow.setContent("hello");
      infowindow.open(map, marker);          
    });

      markers.push(marker);


    }

1 个答案:

答案 0 :(得分:0)

我们第一次看到代码中的infowindow位于:

infowindow.setContent("hello");

什么是infowindow,它创建于何处?就我所见,无处可去。在你的函数的某个地方,在我们创建标记之前,创建它是这样的:

var infowindow = new google.maps.InfoWindow();