Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
17
rated 0 times [  21] [ 4]  / answers: 1 / hits: 18806  / 15 Years ago, mon, april 6, 2009, 12:00:00

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?


More From » google-maps

 Answers
182

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


[#99741] Wednesday, April 1, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
renag

Total Points: 22
Total Questions: 97
Total Answers: 95

Location: Albania
Member since Sun, Nov 22, 2020
4 Years ago
renag questions
Wed, Sep 1, 21, 00:00, 3 Years ago
Thu, Nov 19, 20, 00:00, 4 Years ago
Wed, Nov 6, 19, 00:00, 5 Years ago
Sat, Aug 3, 19, 00:00, 5 Years ago
;