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 7411597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:24:38+00:00 2026-05-29T06:24:38+00:00

just getting my teeth sunk into google maps API. I am attempting to plot

  • 0

just getting my teeth sunk into google maps API.

I am attempting to plot a couple of markers on a map. Done. I am however recycling a variable/object for each marker.

I initially create marker with options and add to map, then take the same marker variable, repurpose it, and add it to map again. This does produce two unique markers with individual title tags.

I want to display an info window for each marker, but am in doubt as to what is the best way to do it. I also see a trouble flag popping up with assigning click events to each marker, as I am using the same variable to add each marker, I am not sure how to add its click event to the unique markers (by name, as name is the same for both, as it never receives any id?)

var marker_obj = new google.maps.Marker({
    position: myLatlng,
    title:"This is Marker 1",
});

marker_obj.setMap(map);

marker_obj = new google.maps.Marker({
    position: myLatlng,
    title:"This is Marker 2",
});

marker_obj.setMap(map);

For creating the info windows, I thought of using one variable/object to keep the info window in, and then repurposing it with new text in each marker click event.

Questions that I have are:

1: Should I use a seperate unique variable/object for each marker (overheads?), if not, how do I identify its click event.

2: Is it fine to repurpose (re-assign) the info window object with new text before its popped, or should I create a unique info window for each marker?

I am a bit of a Java n00b, so any help would greatly be appreciated.

  • 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-05-29T06:24:39+00:00Added an answer on May 29, 2026 at 6:24 am

    You’re on the right lines. Have one infowindow object just as you have one marker object. Then the content of the infowindow changes depending on which marker you click. One thing to watch out for (this also happens if you’re creating markers within a loop), is that the danger is that all the infowindows end up with the content of the last one. So let’s create a new function that updates the content.

    Also, as an aside, you don’t have to call the setMap() function on your marker objects, you can just specify the map attribute in the options you pass when you create the markers.

    var infowindow = new google.maps.InfoWindow({
        content: ''
    });
    
    var marker_obj = new google.maps.Marker({
        position: myLatlng,
        title:"This is Marker 1",
        map: map
    });
    
    bindInfoWindow(marker_obj, map, infowindow, 'Marker 1');
    
    marker_obj = new google.maps.Marker({
        position: myLatlng,
        title:"This is Marker 2",
        map: map
    });
    
    bindInfoWindow(marker_obj, map, infowindow, 'Marker 2');
    

    Then a new function:

    function bindInfoWindow(marker, map, infowindow, html) {
        marker.addListener('click', function() {
            infowindow.setContent(html);
            infowindow.open(map, this);
        });
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I come from a PHP background and I'm just getting my teeth into some
Just getting my feet wet with some Fluent NHibernate AutoMap conventions, and ran into
Just getting into SQL stored queries right now... anyway, here's my database schema (simplified
I'm just getting into creating some WCF services, but I have a requirement to
Just getting into PHP web development. I've got an HTML form where a user
Well just getting into the flow of thing with Python. Reading a few books,
Just getting back into jQuery and JS and I am forgetting the basics.. J(.thSort).click(function()
Just getting started with C++, done a bit of C but one thing I
Just getting into the PhoneGap development on the Mac. I have a .NET service
Just getting off my JavaScript training wheels. Why does Google choose to unescape the

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.