我使用谷歌地图标记。我有信息窗口显示的信息数组。我试过这样的,
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 :(得分:2)
检查以下脚本,确保使用api添加google地图
// 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>
答案 1 :(得分:0)
您在此行的代码中出现错误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);
});
}