Google maps api 3 如何关闭POI';什么是信息窗口?
我试图在单击链接时关闭POI的Google maps api 3 如何关闭POI';什么是信息窗口?,google-maps-api-3,Google Maps Api 3,我试图在单击链接时关闭POI的InfoWindow 我覆盖了InfoWindow的setContent,如下所示: //override the built-in setContent-method google.maps.InfoWindow.prototype.setContent = function (content) { content = content.innerHTML + '<br/> <a href="#" onclick
InfoWindow
我覆盖了InfoWindow的setContent,如下所示:
//override the built-in setContent-method
google.maps.InfoWindow.prototype.setContent = function (content) {
content = content.innerHTML + '<br/> <a href="#" onclick="onSavePlace();">Save place</a>';
//run the original setContent-method
fx.apply(this, arguments);
};
//重写内置的setContent方法
google.maps.InfoWindow.prototype.setContent=函数(内容){
content=content.innerHTML+“
”;
//运行原始的setContent方法
fx.应用(此,参数);
};
注意:我没有创建任何要引用的
InfoWindow
对象来使用close()
方法。在覆盖函数中捕获对InfoWindow的全局引用,以便您可以引用它来关闭它
您对信息窗口的覆盖无效。我从这个问题中提取了一个工作版本:
代码片段:
var地理编码器;
var映射;
var信息窗口;
//保留对原始设置位置功能的参考
var fx=google.maps.InfoWindow.prototype.setPosition;
//从https://stackoverflow.com/questions/24234106/how-to-get-a-click-event-when-a-user-clicks-a-business-place-on-the-map/24234818#24234818
//重写内置的setPosition方法
google.maps.InfoWindow.prototype.setPosition=function(){
//LogaInternal没有文档记录,但看起来
//它只为POI上打开的信息窗口定义
if(this.logaInternal){
//将引用保存在全局infowindow变量中。
infowindow=这个;
google.maps.event.addListenerOnce(这是'map_changed',函数(){
var map=this.getMap();
//信息窗口将打开,通常在点击POI后打开
如果(地图){
//触发点击
google.maps.event.trigger(映射,'click'{
latLng:this.getPosition()
});
}
});
}
//调用原始的setPosition方法
fx.应用(此,参数);
};
函数初始化(){
var map=new google.maps.map(
document.getElementById(“地图画布”){
中心:新google.maps.LatLng(37.4419,-122.1419),
缩放:13,
mapTypeId:google.maps.mapTypeId.ROADMAP
});
google.maps.event.addDomListener(document.getElementById('btn'),'click',函数(e){
//关闭上次打开的POI信息窗口
infowindow.close();
});
}
google.maps.event.addDomListener(窗口“加载”,初始化)代码>
html,
身体,
#地图画布{
身高:100%;
宽度:100%;
边际:0px;
填充:0px
}
Uncaught ReferenceError:fx未定义
var fx=google.maps.InfoWindow.prototype.setContent;