2013-06-24 39 views
1

我試圖添加一個帶有InfoWindow的標記。 標記在兩個地圖中都可見,即街景和法線貼圖。 但是,InfoWindow只能在普通地圖中顯示,而不能在街景視圖中打開時顯示。InfoWindow在街景視圖中不顯示

螢火蟲控制檯沒有錯誤。

代碼:

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()) 
}) 

回答

2

要測試的div是顯示街景圖像或地圖使用:

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

不:

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

(你是不是要求該方法...)

the點擊監聽器應該是:

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

+0

謝謝您的回答,但問題是別的地方,它得到了通過看你的榜樣解決。 我想問你另外一件事,是否有可能在街道的某個高度放置一個標記,比如放在桌子或汽車上面?我可以把它放在道路或地板上,但不能放在物體上。 –

相關問題