街景到infowindow

时间:2012-11-27 16:09:36

标签: google-maps-api-3 infowindow google-street-view

我试图将街景视图显示到infowindow,但我没有得到它,这是我的代码:有谁知道它是如何完成的?

非常感谢先进的

function createMarker(myLatlng) {


var panoramaOptions = {
      position: myLatlng,
      pov: {
        heading: 34,
        pitch: 10,
        zoom: 1
      }
    };
var panorama = new  google.maps.StreetViewPanorama(document.getElementById('pano'),panoramaOptions);
    map.setStreetView(panorama);


var contentString = '<div id="pano" style="width:200px;height:200px;"></div>';
var image = '/artworks/icons/myMarker.png';
var marker = new google.maps.Marker({
  position: myLatlng,
  map: map,
  title: "myTitle",
  icon: image
});

    google.maps.event.addListener(marker, 'click', function() {
    infowindow.setContent(contentString); 
    infowindow.open(map,marker);


    map.setCenter(myLatlng); 
    }); 

return marker;  
}

1 个答案:

答案 0 :(得分:6)

我用:

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而不是它的内容。还记得解开绑定并重新绑定到不同的标记。

相关问题