使用 Google Maps API V3 和 QWebView 时,地图不响应鼠标点击
编辑4
一直以来我都在想这是标记的问题,它们没有被拖动! 现在我意识到,当地图显示在 Qt 小部件中时,鼠标单击在地图上不起作用。
下面的代码,我粘贴在一个 HTML 文件中并通过 Firefox 打开,效果完美!当我点击 QtWidget 上的地图时,同样没有响应:rolleyes:
任何人都可以为我确认这一点或告诉我我做错了什么吗?
Google 地图 JavaScript API 示例
<script type="text/javascript">
var map;
var latlng = new google.maps.LatLng (34.7607233, -117.0107599);
var directionsDisplay = new google.maps.DirectionsRenderer ();;
var directionsService = new google.maps.DirectionsService ();
var pointsArray = new Array();
var arrayToBeReturned = new Array();
function initialize ()
{
var myOptions =
{
zoom:8,
center:latlng,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map (document.getElementById ("map"), myOptions);
directionsDisplay.setMap (map);
google.maps.event.addListener (map, "click", function ()
{
alert("You clicked the map.");
});
}
</script>
</head>
<body onload="initialize()" topmargin="0" leftmargin="0">
<div id="map" style="width: 341px; height: 271px"></div>
<div id="directionsPanel" style="float:right;width:30%;height 100%"></div>
</body>
</html>
EDIT 4
All this while I was thinking that it is the markers problem, that they do not get dragged!
Now I have realized, that NO mouse click works on the map when it is displayed in Qt widget.
The following code, I pasted in an HTML file and opened through Firefox, this worked flawlessly! and the same doesn't respond when I click on the map on QtWidget :rolleyes:
Can anyone confirm this for me or tell me what wrong I am doing?
Google Maps JavaScript API Example
<script type="text/javascript">
var map;
var latlng = new google.maps.LatLng (34.7607233, -117.0107599);
var directionsDisplay = new google.maps.DirectionsRenderer ();;
var directionsService = new google.maps.DirectionsService ();
var pointsArray = new Array();
var arrayToBeReturned = new Array();
function initialize ()
{
var myOptions =
{
zoom:8,
center:latlng,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map (document.getElementById ("map"), myOptions);
directionsDisplay.setMap (map);
google.maps.event.addListener (map, "click", function ()
{
alert("You clicked the map.");
});
}
</script>
</head>
<body onload="initialize()" topmargin="0" leftmargin="0">
<div id="map" style="width: 341px; height: 271px"></div>
<div id="directionsPanel" style="float:right;width:30%;height 100%"></div>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您正在查看事件的错误位置:) 在引用中,每个对象都有自己的事件。您可以在此处查看标记:
[http://code.google.com/apis/maps/documentation/javascript/reference.html#Marker][1]
我已经多次使用了 Dragend 事件,并且工作顺利。
执行此操作的代码可能是:
[1]: http:// /code.google.com/apis/maps/documentation/javascript/reference.html#Markermap = 新
You are looking at the wrong place for the events :) In the references each object have their own events. You can see the ones for markers here:
[http://code.google.com/apis/maps/documentation/javascript/reference.html#Marker][1]
I have used the dragend event plenty of times and it works smoothly.
The code to do it could be:
[1]: http://code.google.com/apis/maps/documentation/javascript/reference.html#Markermap = new
找到解决方案:
在源文件中添加此类,您将在其中“加载”Qt 小部件中的 HTML 文件(包含 Javascript API)。
然后在同一源文件中您自己的类中,添加 setPage 函数调用,如下所示,看看奇迹发生了!
Found the solution:
Add this class in the source file where you are "loading" the HTML file (containing Javascript API) in the Qt widget.
Then in your own class in the same source file, add the setPage function call as shown below and see the magic happen!
点击争论周围的单引号怎么样
How about single quotes around the click arguement