I use:
var contentString = '<div id="content" style="width:250px;height:300px;"></div>';
var infoWindow = new google.maps.InfoWindow({
content: contentString
});
google.maps.event.addListener(marker, "click", function () {
infoWindow.open(mapStyled, marker);
var pano = null;
google.maps.event.addListener(infoWindow, 'domready', function () {
if (pano != null) {
pano.unbind("position");
pano.setVisible(false);
}
pano = new google.maps.StreetViewPanorama(document.getElementById("content"), {
navigationControl: true,
navigationControlOptions: { style: google.maps.NavigationControlStyle.ANDROID },
enableCloseButton: false,
addressControl: false,
linksControl: false
});
pano.bindTo("position", marker);
pano.setVisible(true);
});
google.maps.event.addListener(infoWindow, 'closeclick', function () {
pano.unbind("position");
pano.setVisible(false);
pano = null;
});
尽管我无法立即了解为什么您的代码无法正常工作。就我而言,这是在解析 KML 文件的 for 循环中(从而为每个点创建一个新的弹出窗口和标记)。
希望这可以帮助。
[编辑] 经过反思,问题似乎在于您将“pano”绑定到 div 而不是它的内容。还要记住解除绑定并重新绑定到不同的标记。