2010-03-04 172 views
2

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

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

回答

0

你在你的代码中的错误,在此行GEvent.addListener(marker[i], "click", function(info) {没有这样的阵列

固定代码

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);      
    }); 
} 
+0

antyrat,对于拼写错误感到抱歉。它确实是GEvent.addListener(markers [i],..),现在我编辑它。仍然不起作用。 谢谢 v.srinath – 2010-03-05 04:00:23

+0

我更新我的答案,现在试试。 – antyrat 2010-03-05 11:04:10

+0

你可以显示XML文件的例子吗?我没有看到你创建标记的位置。它必须是这样的:var marker = new GMarker(point); var point = new GLatLng(lat,lng); – antyrat 2010-03-05 11:06:17

2

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

 
    // When the window has finished loading create our google map below 
    google.maps.event.addDomListener(window, 'load', init); 
    function init() 
    { 
    // Basic options for a simple Google Map 
    // For more options see: https://developers.google.com/maps/documentation  //javascript/reference#MapOptions 
    var mapOptions = { 
    // How zoomed in you want the map to start at (always required) 
    zoom: 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>