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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:09:21+00:00 2026-05-17T19:09:21+00:00

I’m making a simple page using Google Maps API 3. My first. One marker

  • 0

I’m making a simple page using Google Maps API 3. My first. One marker with InfoWindow works great. I added a second marker but I can’t get each to display its own InfoWindow. I’m sure it’s simple but it’s not working.

function initialize() {
    var myLatlng = new google.maps.LatLng(37.8736111,-122.4555556);
    var myOptions = {
        zoom: 13,
        center: myLatlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }

    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);


    // Marker1  
    var marker1 = new google.maps.LatLng(37.8736111,-122.4555556);

    var contentString1 = '<div id="content">'+
    '<div id="siteNotice">'+
    '</div>'+
    '<h2 id="firstHeading" class="firstHeading">Blackie&#8217;s Pasture</h1>'+
    '<div id="bodyContent">'+
    '<p><b>Historical Marker No. 1</b></p> '+
    '<p>The pasture where Blackie lived </p> '+
    '<a href="images/harvey.jpg" alt="Harvey" width="185" height="209" target="_blank">' +
    '<img src="images/harvey.jpg" alt="Harvey" width="93" height="104"  /></a>' +
    '<img src="images/marker-test.jpg" alt="Marker placque" width="93" height="104"  /></a><br />' +
    '<em>Click on a photo to enlarge it</em>' +
'</div>'+
    '</div>';   

    var infowindow = new google.maps.InfoWindow({
        content: contentString1
    });

var marker1 = new google.maps.Marker({
        position: marker1,
        map: map,
        title: "Blackie's Pasture"
    });

google.maps.event.addListener(marker1, 'click', function() {
        infowindow.open(map, marker1);
    });

    // Marker2
var marker2 = new google.maps.LatLng(37.8837959515249951,-122.46597290039062);

var contentString2 = '<div id="content">'+
    '<div id="siteNotice">'+
    '</div>'+
    '<h2 id="firstHeading" class="firstHeading">Marker Number 2</h1>'+
    '<div id="bodyContent">'+
    '<p><b>The second marker</b></p> '+
    '<p>Just another place </p> '+
    '<a href="images/harvey.jpg" alt="Harvey" width="185" height="209" target="_blank">' +
    '<img src="images/harvey.jpg" alt="Harvey" width="93" height="104"  /></a>' +
    '<img src="images/marker-test.jpg" alt="Marker placque" width="93" height="104"  /></a><br />' +
    '<em>Click on a photo to enlarge it</em>' +
    '</div>'+
    '</div>';

    var infowindow = new google.maps.InfoWindow({
        content: contentString2
    });

var marker2 = new google.maps.Marker({
        position: marker2,
        map: map,
        title: "Marker Number 2"
    });


    google.maps.event.addListener(marker2, 'click', function() {
        infowindow.open(map,marker2);
    });
}
  • 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-17T19:09:22+00:00Added an answer on May 17, 2026 at 7:09 pm

    You’re missing a semicolon,* and you’re defining marker1 and marker2 as LatLngs, and then later overwriting them with Markers…

    …but here’s what’s really killing you: you’re overwriting the infowindow variable. Try this code out (tested briefly in the code playground):

    function initialize() {
        var myLatlng = new google.maps.LatLng(37.8736111, -122.4555556);
        var myOptions = {
            zoom: 13,
            center: myLatlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        }
    
        var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    
        // Marker1  
        var latLng1 = new google.maps.LatLng(37.8736111, -122.4555556);
    
        var contentString1 = '<div id="content"><div id="siteNotice"></div><h2 id="firstHeading" class="firstHeading">Blackie&#8217;s Pasture</h1><div id="bodyContent"><p><b>Historical Marker No. 1</b></p> <p>The pasture where Blackie lived </p> <a href="images/harvey.jpg" alt="Harvey" width="185" height="209" target="_blank"><img src="images/harvey.jpg" alt="Harvey" width="93" height="104" /></a><img src="images/marker-test.jpg" alt="Marker placque" width="93" height="104" /></a><br /><em>Click on a photo to enlarge it</em></div></div>';
    
        var infowindow1 = new google.maps.InfoWindow({
            content: contentString1
        });
    
        var marker1 = new google.maps.Marker({
            position: latLng1,
            map: map,
            title: "Blackie's Pasture"
        });
    
        google.maps.event.addListener(marker1, 'click', function() {
            infowindow1.open(map, marker1);
        });
    
        // Marker2
        var latLng2 = new google.maps.LatLng(37.8837959515249951, -122.46597290039062);
    
        var contentString2 = '<div id="content"><div id="siteNotice"></div><h2 id="firstHeading" class="firstHeading">Marker Number 2</h1><div id="bodyContent"><p><b>The second marker</b></p> <p>Just another place </p> <a href="images/harvey.jpg" alt="Harvey" width="185" height="209" target="_blank"><img src="images/harvey.jpg" alt="Harvey" width="93" height="104" /></a><img src="images/marker-test.jpg" alt="Marker placque" width="93" height="104" /></a><br /><em>Click on a photo to enlarge it</em></div></div>';
    
        var infowindow2 = new google.maps.InfoWindow({
            content: contentString2
        });
    
        var marker2 = new google.maps.Marker({
            position: latLng2,
            map: map,
            title: "Marker Number 2"
        });
    
        google.maps.event.addListener(marker2, 'click', function() {
            infowindow2.open(map, marker2);
        });
    }​
    

    This type of error is really easy to catch with a static code analysis tool like jslint.


    *A minor problem, until you minify your code – then it’s a bigger problem

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.