【问题标题】:info window for marker标记的信息窗口
【发布时间】:2016-09-04 17:20:00
【问题描述】:

我使用谷歌地图标记。我有一系列信息要在信息窗口中显示。我试过这样,

markers = xml.documentElement.getElementsByTagName("marker");

for (i = 0; i < markers.length; i++) 
{

    info = markers[i].getAttribute("info");
    GEvent.addListener(markers[i], "click", function(info) {
          this.openInfoWindowHtml(info);                      
    });
}

openInfoWindowHtml(info) 必须为每个标记显示。我需要显示信息窗口。

谢谢 v.srinath

【问题讨论】:

    标签: google-maps


    【解决方案1】:

    检查以下脚本,确保使用 api 添加谷歌地图

    // 当窗口完成加载后,在下面创建我们的谷歌地图 google.maps.event.addDomListener(window, 'load', init); 函数初始化() { // 简单谷歌地图的基本选项 // 更多选项参见:https://developers.google.com/maps/documentation //javascript/reference#MapOptions var mapOptions = { // 您希望地图开始的放大方式(始终需要) 缩放:4, // The latitude and longitude to center the map (always required) center: new google.maps.LatLng(25.985448,52.7994103), // Main map location navigationControl: false, mapTypeControl: false, scaleControl: false, draggable: false, scrollwheel: false, mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR, position: google.maps.ControlPosition.BOTTOM_LEFT }, // How you would like to style the map. // This is where you would paste any style found on Snazzy Maps. styles: [] }; // Get the HTML DOM element that will contain your map // We are using a div with id="map" seen below in the <body> var mapElement = document.getElementById('googlemap'); // Create the Google Map using our element and options defined above var map = new google.maps.Map(mapElement, mapOptions); // address content Kuwait var location1 = '<div id="content">'+ '<div id="siteNotice">'+ '</div>'+ '<h1 id="firstHeading" class="firstHeading">Location1 name</h1>'+ '<div id="bodyContent">'+ '<p> Location 1 content' + '</p>'+ '</div>'+ '</div>'; var infolocation1 = new google.maps.InfoWindow({ content: location1 }); // Location Kuwait var marker1 = new google.maps.Marker({ position: new google.maps.LatLng(29.363765,47.966278), map: map, title: '' }); marker1.addListener('click', function() { infolocation1.open(map, marker1); }); // address content Kuwait var location2 = '<div id="content">'+ '<div id="siteNotice">'+ '</div>'+ '<h1 id="firstHeading" class="firstHeading"> Location2 name</h1>'+ '<div id="bodyContent">'+ '<p> Location 2 content' + '</p>'+ '</div>'+ '</div>'; var infolocation2 = new google.maps.InfoWindow({ content: location2 }); // Location Kuwait var marker2 = new google.maps.Marker({ position: new google.maps.LatLng(29.363765,47.966278), map: map, title: '' }); marker2.addListener('click', function() { infolocation2.open(map, marker2); }); } </pre>

    【讨论】:

      【解决方案2】:

      您的代码在这一行有错误GEvent.addListener(marker[i], "click", function(info) { 没有这样的数组marker

      固定代码是

      markers = xml.documentElement.getElementsByTagName("marker");
      
      for (i = 0; i < markers.length; i++) 
      {
      
          info = markers[i].getAttribute("info");
          GEvent.addListener(markers[i], "click", function() {
                markers[i].openInfoWindowHtml(info);                      
          });
      }
      

      【讨论】:

      • antyrat,抱歉拼写错误。它确实是 GEvent.addListener(markers[i],..),现在我编辑了它。还是不行。谢谢 v.srinath
      • 你能展示 XML 文件的例子吗?我看不到你在哪里创建标记。它必须是这样的: var marker = new GMarker(point);其中 var point = new GLatLng(lat,lng);
      • geocoder.getLocations(....markers = xml.documentElement.getElementsByTagName("marker"); location3 = //来自地理编码器 for (i = 0 ; i
      猜你喜欢
      • 2016-07-09
      • 2016-07-27
      • 2013-09-02
      • 2021-12-15
      • 2015-04-11
      • 1970-01-01
      • 2017-08-27
      • 2011-08-21
      • 2013-04-17
      相关资源
      最近更新 更多