2012-10-27 85 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); 
} 
相关问题