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

  • Home
  • SEARCH
  • 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 8853439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:39:10+00:00 2026-06-14T13:39:10+00:00

I have downloaded some samples for Google maps API 3 and I can see

  • 0

I have downloaded some samples for Google maps API 3 and I can see some code like bellow:

(function (i, marker) {
    google.maps.event.addListener(marker, 'click', function () {
        if (!infowindow) {
            infowindow = new google.maps.InfoWindow();
        }
        infowindow.setContent("Message" + i);
        infowindow.open(map, marker);
    });
})(i, marker);

Could some one explain me what this means? Or can we re-write the above code in different ways? I am bit new to JavaScript and don’t know what exactly the above code does?

here is the full script

function markicons() {

    InitializeMap();

    var ltlng = [];

    ltlng.push(new google.maps.LatLng(17.22, 78.28));
    ltlng.push(new google.maps.LatLng(13.5, 79.2));
    ltlng.push(new google.maps.LatLng(15.24, 77.16));

    map.setCenter(ltlng[0]);



    for (var i = 0; i <= ltlng.length; i++) {
        marker = new google.maps.Marker({
            map: map,
            position: ltlng[i]
        });

        (function (i, marker) {

            google.maps.event.addListener(marker, 'click', function () {

                if (!infowindow) {
                    infowindow = new google.maps.InfoWindow();
                }

                infowindow.setContent("Message" + i);

                infowindow.open(map, marker);

            });

        })(i, marker);

    }

}
  • 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-14T13:39:11+00:00Added an answer on June 14, 2026 at 1:39 pm

    This code is assigning the click event handler on given marker so that when clicked, new information window pops up with the text “Message” followed by what looks to be the marker index.

    Most likely this code is part of a loop over all the markers.

    If I understand your goal correctly, add such function to your code:

    function AssignMarkerClick(marker, index) {
        google.maps.event.addListener(marker, 'click', function () {
            if (!infowindow) {
                infowindow = new google.maps.InfoWindow();
            }
    
            infowindow.setContent("Message" + index);
            infowindow.open(map, marker);
        });
    }
    

    Then change your loop to this:

    for (var i = 0; i <= ltlng.length; i++) {
        marker = new google.maps.Marker({
            map: map,
            position: ltlng[i]
        });
        AssignMarkerClick(marker, i);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have downloaded an sample code, so there are some CString variables in that
I have downloaded some files from the internet related to a particular topic. Now
Hey I have downloaded one of the xml editors from some site. But don't
I have some demos that I downloaded and they come with a Makefile.win and
I have a project that depends upon some other binaries to be downloaded from
I have downloaded some sample source codes, modified them and made a audio-video player.
I have some code that needs to work with X509 Certificate information. I have
I have downloaded the javafx 2 samples and want to run in from its
I would like to start programming for symbianOS and have some starter questions.I am
Am new to SQLite using in iPhone. I have used google and got some

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.