Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8125815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:56:27+00:00 2026-06-06T06:56:27+00:00

I’ve successfully added a handler to the click event of polylines I’ve added to

  • 0

I’ve successfully added a handler to the click event of polylines I’ve added to Google Maps (V3) if I code them to be added one at a time, but if I make a for loop to simply iterate through my data, it fails.

Working demos:

http://www.ikfoundation.org/demo/works.html

http://www.ikfoundation.org/demo/fails.html

Code is identical on each apart from the bit that draws the lines:

Works:

var linePts = [[
new google.maps.LatLng(59.454924068851290, 17.094726562500000),
    new google.maps.LatLng(55.984639327677950, 17.270507812500000),
      ],[
new google.maps.LatLng(51.081191044453350, 26.938476562500000),
new google.maps.LatLng(62.112946929861720, 26.586914062500000)
      ]];

// Draw the lines...  

elines[0] = new google.maps.Polyline({
        path: linePts[0],
        strokeColor: "#0000ff",
        strokeOpacity: 1.00,
        strokeWeight: 7,
        clickable: true,
        editable: true,
        geodesic: true,
        zIndex: 1,
        map: map,
        myID: 0
    });



google.maps.event.addListener(elines[0], 'click', function()
{
    lineClick(elines[0]);
});

elines[1] = new google.maps.Polyline({
        path: linePts[1],
        strokeColor: "#0000ff",
        strokeOpacity: 1.00,
        strokeWeight: 7,
        clickable: true,
        editable: true,
        geodesic: true,
        zIndex: 1,
        map: map,
        myID: 1
    });

google.maps.event.addListener(elines[1], 'click', function()
    {
        lineClick(elines[1]);
    });

function lineClick(line)
{
    alert("Line clicked with myID=" + line.myID);
}

Fails (i excluded the same line point definition array which is identical to that shown abovem, and the lineClick function, again identical in both):

for (var i=0; i<=1; i++)
{       
elines[i] = new google.maps.Polyline({
            path: linePts[i],
            strokeColor: "#0000ff",
            strokeOpacity: 1.00,
            strokeWeight: 7,
            clickable: true,
            editable: true,
            geodesic: true,
            zIndex: 1,
            map: map,
            myID: i 
        });

google.maps.event.addListener(elines[i], 'click', function()
        {
            lineClick(elines[i]);
        });
}

What have I done wrong? Both are using the same exact variable names and indexes in those variables. And everything works perfectly as you can see in my example links, apart from the click listener. Which fails in the latter “fails” version because it seems that the polyline is not being passed at all to the lineClick function (you need to run a java debugger to see the error).

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T06:56:29+00:00Added an answer on June 6, 2026 at 6:56 am

    Sorted it out. Don’t understand why (anyone care to elighten?) but replacing the addListener code with the following makes it work:

            google.maps.event.addListener(elines[i], 'click', function()
            {
                lineClick(this);
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need to clean up various Word 'smart' characters in user input, including but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.