Google Maps API v3添加多个标记w/info windows w/custom text

Nad*_*r S 6 javascript infowindow google-maps-api-3 marker

我正在制作一个关于在挪威遇害的骑车人的网站.对于我的项目,我一直在使用谷歌地图api v3,但我对javascript有着模糊的熟悉.您可以在此处查看我的结果:http://salamatstudios.com/googlemapstest/

基本上我想在每个标记上都有多个带有infowindows的标记.每个infowindows将包含:姓名(年龄),位置,死亡日期,阅读更多(将链接到网站本身的页面).

就像这个例子:http://salamatstudios.com/bicycles/

我尝试使用一个标记和infowindow,并且工作得很好.当我想添加带有自定义信息窗口的新标记时,我就会卡住.目前,我在第一个链接中看到了不同位置的3个标记,但是当我单击标记时,没有任何信息窗口出现.

如何绕过它来编码它以便出现信息?我怎样才能在每个infowindow中都有自定义文本?完成后,我将在地图上有大约30-40个标记.所有信息窗口都有不同类型的信息.

function initialize() {
    var mapOptions = {
      center: new google.maps.LatLng(65.18303, 20.47852),
      zoom: 5,
      mapTypeId: google.maps.MapTypeId.ROADMAP,


      // MAP CONTROLS (START)
      mapTypeControl: true,

      panControl: true,
      panControlOptions: {
      position: google.maps.ControlPosition.TOP_RIGHT
      },

      zoomControl: true,
      zoomControlOptions: {
      style: google.maps.ZoomControlStyle.LARGE,
      position: google.maps.ControlPosition.LEFT_TOP
      },

      streetViewControl: true,
      streetViewControlOptions: {
      position: google.maps.ControlPosition.LEFT_TOP
      },
      // MAP CONTROLS (END)



    };
    var map = new google.maps.Map(document.getElementById("map"),
        mapOptions);


    // -------------- MARKER 1
    var marker1 = new google.maps.Marker({
    position: new google.maps.LatLng(59.96384, 11.04120),
    map: map,
    icon: 'img/bike5.png'
    });


    // MARKER 1'S INFO WINDOW
    var infowindow1 = new google.maps.InfoWindow({
    content: 'Name<br />Location<br />Date<br /><br /><a href="http://www.db.no" target="_blank">Read more(test link)</a>'
    });
    // End of infowindow code

    // Adding a click event to the marker
    google.maps.event.addListener(marker1, 'click', function() {
    // Calling the open method of the infoWindow
    infowindow1.open(map, marker);
    });
    // -------- END OF 1st MARKER


    // -------------- MARKER 2
    var marker2 = new google.maps.Marker({
    position: new google.maps.LatLng(60.63040, 8.56102),
    map: map,
    icon: 'img/bike5.png'
    });

    // MARKER 2'S INFO WINDOW
    var infowindow2 = new google.maps.InfoWindow({
    content: 'Name<br />Location<br />Date<br /><br /><a href="http://www.db.no" target="_blank">Read more(test link)</a>'
    });
    // End of infowindow code

    // Adding a click event to the marker
    google.maps.event.addListener(marker2, 'click', function() {
    // Calling the open method of the infoWindow
    infowindow2.open(map, marker);
    });
    // -------- END OF 2nd MARKER


    // -------------- MARKER 3
    var marker3 = new google.maps.Marker({
    position: new google.maps.LatLng(60.39126, 5.32205),
    map: map,
    icon: 'img/bike5.png'
    });

    // MARKER 3'S INFO WINDOW
    var infowindow3 = new google.maps.InfoWindow({
    content: 'Name<br />Location<br />Date<br /><br /><a href="http://www.db.no" target="_blank">Read more(test link)</a>'
    });
    // End of infowindow code

    // Adding a click event to the marker
    google.maps.event.addListener(marker3, 'click', function() {
    // Calling the open method of the infoWindow
    infowindow3.open(map, marker);
    });
    // -------- END OF 3rd MARKER


  }
  google.maps.event.addDomListener(window, 'load', initialize);
Run Code Online (Sandbox Code Playgroud)

如果有人能给我一些线索,那将会很棒.我试过一下,但我找不到答案.提前致谢!:-)

geo*_*zip 9

您需要将infowindow附加到正确的标记.目前它们都与"标记"相关联,但它不存在(并且当您单击标记时应该在javascript控制台中导致错误消息).

在点击监听器内部更改:

infowindow1.open(map, marker);

infowindow2.open(map, marker);

infowindow3.open(map, marker);
Run Code Online (Sandbox Code Playgroud)

至:

infowindow1.open(map, marker1);

infowindow2.open(map, marker2);

infowindow3.open(map, marker3);
Run Code Online (Sandbox Code Playgroud)

工作实例