当您在Google地图上点击某个POI时,系统内置信息窗口将由地图引擎打开。 你如何获得对该窗口的引用(我想在地图上点击下一个关闭它)。如何引用系统信息窗口
0
A
回答
2
已经有一些类似的问题之前:
- How to get a click event when a user clicks a (business) place on the map
- click event listener on styled map icons and labels
的方法有覆盖信息窗口原型的方法来得到一个参考,适应代码:
//run this after loading the maps-api
(function(){
var fx = google.maps.InfoWindow.prototype.setContent;
//override the built-in setContent-method
google.maps.InfoWindow.prototype.setContent = function() {
//this property isn't documented, but as it seems
//it's only defined for InfoWindows opened on POI's
if (this.logAsInternal) {
google.maps.event.addListenerOnce(this, 'map_changed',function() {
var map = this.getMap(),that=this;
//attach the click-handler when the infowindow opens
if (map) {
google.maps.event.addListenerOnce(map, 'click', function(){that.close();});
}
});
}
//call the original setContent-method
fx.apply(this, arguments);
};})();
3
这是在Google Maps API问题跟踪器中跟踪的问题#4797,最近已修复,并在3.26版中提供。
从版本3.26开始,您应该听取Map对象上的“click”事件。如果用户点击POI,则会引发IconMouseEvent。该类扩展了Regular MouseEvent并包含一个名为placeId的属性。所以你可以检查事件对象是否定义了placeId。 placeId字段当然包含Place ID,您可以使用Places API来获取点击图标的更多信息。
我准备了一个小的演示:http://jsbin.com/parapex/10/edit?html,output
总之你的地图“单击”事件处理程序应该是这样的:
// This is the click event handler
var handleClick = function(event) {
// If the event has a placeId, use it.
if (event.placeId) {
// Calling e.stop() on the event prevents the default info window
// from showing.
// If you call stop here when there is no placeId you will prevent
// some other map click event handlers from receiving the event.
event.stop();
// do something with event.placeId here. Like calling places service
}
};
相关问题
- 1. 信息系统
- 2. 自定义信息窗口只显示在android系统
- 3. Laravel系统信息
- 4. Go/Golang试图通过系统调用获取窗口信息。 (如在EnumWindows等)
- 5. 如何通过信息窗口向用户提供信息
- 6. 信息窗口gmaps
- 7. OnMapRedady信息窗口
- 8. markerclusterer信息窗口
- 9. 文件系统信息 - 如何查询?
- 10. 窗口系统如何通知QApplication?
- 11. 如何获取有关系统视图索引的信息
- 12. 如何清除gmaps信息窗口
- 13. 如何显示信息窗口?
- 14. 如何包括信息窗口
- 15. 如何使用Java在kubuntu中监视系统统计信息?
- 16. 如何使用node.js获取系统统计信息
- 17. 捕获系统信息
- 18. 系统信息与DOS
- 19. Sys系统::信息 - 问题
- 20. 信息系统设计
- 21. 查找系统信息
- 22. Visual Basic系统信息
- 23. 创建信息系统图
- 24. 在线信息系统
- 25. 信息检索系统
- 26. 批量系统信息?
- 27. 没有窗口系统
- 28. 概述系统窗口
- 29. 发送信息WPF窗口
- 30. Google Map API信息窗口
您不能引用的。 – geocodezip
这样一个很好的评论倒票和近距离投票。 – Kolyunya
可能的重复[在谷歌地图API中使用原生infoWindows中有趣的地方](http://stackoverflow.com/questions/21202034/work-with-native-infowindows-of-interesting-places-in-google-maps- api/21884991#21884991) – geocodezip