我正在创建一个项目,我想在其中添加信息窗口,以便在Google地图API中移动标记。 I have added info window as shown in image 但是我无法在船上添加相同的东西。
在线标记代码:
for (var i = 0; i < DrivePath.length-1; i++) {
var line = new google.maps.Polyline({
path: [DrivePath[i], DrivePath[i+1]],
icons: [
{
icon: symbolShape,
offset: '0%'
}
],
strokeColor: Colors[i],
strokeOpacity: 0.0,
strokeWeight: 2,
map: map
});
lineArray[i] = line;
google.maps.event.addListener(line, 'click', function() {
infowindow.open(map,line);
});
}
for (var i = 0; i < DrivePath.length-1; i++) {
line1 = new google.maps.Polyline({
path: [DrivePath[i], DrivePath[i+1]],
icons: [
{
icon: symbolSource,
offset: '0%'
}, {
icon: symbolDestination,
offset: '100%'
}
],
strokeColor: Colors[i],
strokeOpacity: 1.0,
strokeWeight: 2,
map: map
});
lineArray1[i] = line1;
}
console.log(lineArray.length);
console.log(lineArray1.length);
//Map boundaries
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < line.getPath().getLength(); i++) {
bounds.extend(line.getPath().getAt(i));
}
map.fitBounds(bounds);
整个代码都在 JSFiddle.