2012-10-27 86 views
4

根據文檔,infoWindow標記是可選的,那麼請問如何實現?我試過infowindow.open(地圖)infowindow.open(map,null)但都沒有產生任何東西。Google地圖沒有標記的infoWindow?

+0

你想要什麼,並和你嘗試過什麼,張貼在這裏的代碼沒有問題。 –

回答

4

infowindow.open(map)是沒有意義的,因爲您需要指定infowindow應該打開的位置,還有一個錐形的莖幹,它指定了它應該指向的位置。

根據Infowindows的documentation-InfoWindows可以附加到標記對象(在這種情況下,它們的位置基於標記的位置),或者在地圖本身的指定LatLng上。

所以,如果你想DONOT標記打開信息窗口,使用地圖點擊事件 -

var iwindow= new google.maps.InfoWindow; 
    google.maps.event.addListener(map,'click',function(event) 
    { 
     iwindow.setContent(event.latLng.lat()+","+event.latLng.lng()); 
     iwindow.open(map,this); 
     iwindow.open(map,this); 
    }); 

,並關閉一個InfowWindow- infowindow.setMap(null);

。希望清除你的疑慮。

+0

非常感謝,正是我所需要的。 – Archdeacon

+0

歡迎。 Plz考慮通過點擊解決方案旁邊的勾號來標記答案:) – Cdeez

5

如果位置設置,存在一個顯示信息窗口

function initMap() { 
    var map = new google.maps.Map(document.getElementById('map'), { 
    zoom: 6, 
    center: {lat: 55.6761, lng: 12.5683}, 
    mapTypeId: google.maps.MapTypeId.TERRAIN 
}); 
var infowindow = new google.maps.InfoWindow({ 
    content: "Copenhagen" 
}); 
infowindow.setPosition({lat: 55.6761, lng: 12.5683}); 
infowindow.open(map); 
} 
相關問題