InfoWindow不会显示在街景视图中

时间:2013-06-24 09:50:25

标签: google-maps-api-3

我正在尝试添加附加InfoWindow的标记。 标记在两个地图中都可见,即街景和法线贴图。 但是,InfoWindow只会在普通地图中显示,但在街景中打开时则不会显示。

firebug控制台没有错误。

代码:

var a = google.maps;
var b = {
    center: new a.LatLng(parseFloat(ll[0]),parseFloat(ll[1])),
    zoom: zoom,
    mapTypeId: a.MapTypeId.ROADMAP,
    streetViewControl: true,
    mapTypeControlOptions: {
        mapTypeIds: [a.MapTypeId.ROADMAP, a.MapTypeId.SATELLITE, a.MapTypeId.TERRAIN]
    },
    panControl: false,
    zoomControlOptions: {
        style: a.ZoomControlStyle.SMALL
    }
};
map = new a.Map(document.getElementById("map-canvas"), b);

panorama = map.getStreetView();
panorama.setPosition(new google.maps.LatLng(42.345573,-71.098326));
panorama.setPov(/** @type {google.maps.StreetViewPov} */({
    heading: 270,
    pitch: 0
}));
panorama.setVisible(false);

iw = new a.InfoWindow();
a.event.addListener(map, "click", function () {
    if (iw) iw.close()
});

var g = new a.Marker({
        position: c,
        map: map,
        clickable: true,
        draggable: true,
        optimized: false,
        raiseOnDrag: false,
        zIndex: highestOrder()
    });

var description = "<h2>"+document.getElementById('marker-title').value+"</h2><br/><p style='width:200px;'>"+document.getElementById('marker-desc').value+"</p>";

a.event.addListener(g, "click", function () {
    actual = g;
    iw.setContent(description);
    if(map.getStreetView().getVisible == true) {
        iw.open(map.getStreetView(), this);
    }
    else {
        iw.open(map, this);
    }
});

a.event.addListener(g, "dragstart", function () {
    if (actual == g) iw.close();
    z_index += 1;
    g.setZIndex(highestOrder())
})

1 个答案:

答案 0 :(得分:2)

要测试div是否显示街景图像或地图使用:

if (map.getStreetView().getVisible()) {

if(map.getStreetView().getVisible == true) {

(你没有调用方法......)

点击监听器应为:

a.event.addListener(g, "click", function () {
  actual = g;
  if (map.getStreetView().getVisible()) {
    iw.setContent(description);
    iw.open(map.getStreetView(), this);
  } else {
    iw.setContent(description);
    iw.open(map, this);
  }
});

working example