如何检测Google地图PolyLine叠加层上的点击事件? [英] How do I detect a click event on a google maps PolyLine overlay?
问题描述
在我看来,我应该能够执行以下操作来检测Google地图上一行上的点击事件:
var line = new GPolyline(...);
map.addOverlay(line);
GEvent.addListener(line,click,function(latlng){alert(clicked);});
api reference 表示这个版本在2.88版本中可用,该版本于2007年发布(!?),所以我假设这就是我使用,但我不知道如何确认。
我也尝试设置 {clickable:true}
选项(它应该是默认设置)。我已经在FireFox 3和Opera 9.6中进行了测试,所以不要怀疑它是浏览器特定的。我在页面上也使用了jQuery。
我有足够的代码来检测点击标记的效果,点击行会非常好,任何人都可以启发我?
我刚做了一个快速测试,下面的代码在我的测试页上工作:
var polyline = new GPolyline([
new GLatLng(37.4419,-122.1419),
new GLatLng(37.4519,-122.1519)
],#ff0000,10);
map.addOverlay(polyline);
GEvent.addListener(折线,'click',function(){
alert('你点击折线');
});
告诉您的谷歌地图版本的方法是查看v =的参数google maps src url you have
http://maps.google.com/maps?file=api&v=2&key=MY_API_KEY
在这种情况下,我有v = 2,这意味着我正在使用最新的stable 2版本,它支持可点击多段线(截至今天2.101是最新版本)。 v = 2.x表示您正在使用边缘版本。并且任何v = 2.5,句点(。)之后的任何内容都是数字,表示特定版本
It seems to me that I should be able to do the following to detect a click event on a line on a google map:
var line = new GPolyline( ... );
map.addOverlay(line);
GEvent.addListener(line, "click", function(latlng){ alert("clicked"); });
The api reference says this is available in version 2.88, which was released in 2007(!?), so I'm assuming that's what I'm using, but I don't know how to confirm that.
I also tried setting the {clickable:true}
option explicitly (it's supposed to be the default.) I've tested in FireFox 3 and Opera 9.6 so doubt it's browser specific. I'm also using jQuery on the page.
I have plenty of code detecting clicks on markers that works fine, clicking on lines would be really nice, can anyone enlighten me?
I just did a quick test and the following code worked on my test page:
var polyline = new GPolyline([
new GLatLng(37.4419, -122.1419),
new GLatLng(37.4519, -122.1519)
], "#ff0000", 10);
map.addOverlay(polyline);
GEvent.addListener(polyline, 'click', function() {
alert('you clicked polyline');
});
The way to tell what version of google maps you have is to look at the v= parameter of the google maps src url you have
http://maps.google.com/maps?file=api&v=2&key=MY_API_KEY
In this case I have "v=2", that means I am using the latest stable 2 version, which supports clickable polylines (as of today 2.101 is the most recent release). "v=2.x" means you are using an edge release. And any "v=2.5" where the anything after the period (.) is a number refers to a specific release
这篇关于如何检测Google地图PolyLine叠加层上的点击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!