问题描述
根据文档,标记是infoWindow的可选标记,那么如何实现?我已经尝试过 infowindow.open(map)和 infowindow.open(map,null),但是都不会产生任何效果.
According to the documention a marker is optional with an infoWindow, so how is this achieved please? I have tried infowindow.open(map) and infowindow.open(map,null) but both produce nothing.
推荐答案
infowindow.open(map)
没有意义,因为您需要指定信息窗口应打开的位置,并且它还具有一个锥形茎杆,用于指定应该指向的位置
infowindow.open(map)
makes no sense since you need to specify the position where the infowindow should open, also it has a tapered stem which specifies the location where it should point.
根据Infowindows的文档 可以附加到Marker对象(在这种情况下,它们的位置取决于标记的位置),也可以附加到指定LatLng上的地图本身.
According to the documentation of Infowindows- InfoWindows may be attached to either Marker objects (in which case their position is based on the marker's location) or on the map itself at a specified LatLng.
因此,如果您不希望标记打开信息窗口,请使用地图点击事件-
So if you donot want the marker to open the infowindow, use the map click event-
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);
And to close a InfowWindow- infowindow.setMap(null);
希望可以消除您的疑虑.
Hope that cleared your doubts.
这篇关于没有标记的Google Maps infoWindow?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!