我需要在一个信息窗口上显示不同的数据,当有人点击一个可用的折线时,弹出一个信息窗口,
我已经为此研究了许多解决方案,这是我遇到的一个例子,
Google Maps API - 数组和 InfoWindows 的问题
但是这个解决方案似乎对我不起作用,当我单击折线时它不显示信息窗口。请帮助我...我使用了不同的代码,它只显示数组的最后一个元素..我所做的是我通过 for 循环添加折线。请帮我解决这个问题..这是我的代码,
var map;
var polylinesIn = [];
var infowindow = new google.maps.InfoWindow();
var infowindowArray = [];
function initialize() {
var styles = [{ featureType: "landscape", stylers: [{ color: "#000514"}] }, { featureType: "administrative.country", stylers: [{ weight: 0.1 }, { color: "#009acd"}] }, { featureType: "water", stylers: [{ color: "#1f4fa5dc"}] }, { featureType: "road", stylers: [{ color: "#000514"}] }, { featureType: "administrative.locality", stylers: [{ color: "#7cfc00" }, { visibility: "off"}] }, { featureType: "landscape.man_made", stylers: [{ visibility: "off"}] }, { featureType: "poi", stylers: [{ visibility: "off"}] }, { featureType: "administrative.province", stylers: [{ visibility: "on"}]}];
var mapOptions = {
center: new google.maps.LatLng(7.3, 80.6333),
zoom: 3,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
mapOptions);
map.setOptions({ styles: styles });
var lineSymbolIn = {
path: google.maps.SymbolPath.CIRCLE,
scale: 2,
strokeColor: '#FF8000'
};
for (var i = 0; i < 5; i = i + 1) {
var conentVal = i.toString();
//var infowindow = new google.maps.InfoWindow();
var netTrafficIn = [
new google.maps.LatLng(53.3333866 + i, -6.247401 + i),
new google.maps.LatLng(7.3, 80.6333)];
var polylineIn = new google.maps.Polyline({
path: netTrafficIn,
icons: [{ icon: lineSymbolIn, offset: '100%'}],
strokeColor: " #FF8000",
strokeOpacity: 1.0,
strokeWeight: 1,
geodesic: true
});
polylineIn.setMap(map);
polylinesIn[i]=polylineIn;
animateCircleIn(i);
addInfowindow(i.toString());
createInfoWindow(i);
}
}
function addInfowindow(contentVal) {
infowindow = new google.maps.InfoWindow({ content: contentVal });
infowindowArray.push(infowindow);
}
function createInfoWindow(id) {
google.maps.event.addListener(polylinesIn[id], 'click', (function (id) {
return function () {
infowindowArray[id].open(map, polylinesIn[id]);
}
})(id));
}
function animateCircleIn(id) {
var count = 0;
offsetId = window.setInterval(function () {
count = (count + 1) % 200;
var icons = polylinesIn[id].get('icons');
icons[0].offset = (count / 2) + '%';
polylinesIn[id].set('icons', icons);
}, 20);
}
非常感谢 :)
好吧,我做了一些更改,就像 yal 建议的那样,但仍然没有出现 infowindows..请帮助..非常感谢 :)