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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:28:00+00:00 2026-06-02T17:28:00+00:00

I have several markers on my google map. Each has text that should show

  • 0

I have several markers on my google map. Each has text that should show when it is clicked in the form of an infowindow. The code for all this is below. Hwever, the problem is that, when I click any marker on the map, its always the same marker that the map zooms in on and the same marker’s infoWindow pops up. No matter where I click its always the same.

Wondering if there is something in plain sight that Im doing wrong. Could someone give me some advice?

  function getlistings()  
   {  
     $.getJSON('list/listings.json', processlistings);  
   }  



function processlistings(data)   
{  
    listings = data;  
    markersArray = [];  
    for( i = 0; i < listings.length; i++)   
    {  
        var listing = listings[i];  
        var markerLatLng = new google.maps.LatLng(parseFloat(listing["latitude"]), parseFloat(listing["longitude"]));  
        marker = new google.maps.Marker({  
            position : markerLatLng,  
            title: listing['name'],  
            map : map  
        });  

    var infowindow = new google.maps.InfoWindow(  
        {  
          content: listing['name'],  
          position: markerLatLng  
        });  

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

    });  

    markersArray.push(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-02T17:28:02+00:00Added an answer on June 2, 2026 at 5:28 pm

    When you loop through your data, you are creating an InfoWindow many times over. At the end of the loop, you have one InfoWindow at markerLatLng.

    When the marker is clicked, infowindow.open() is called, which uses the infowindow at markerLatLng.

    You need to use a function closure, as demonstrated at http://www.geocodezip.com/v3_MW_example_map1.html

    //loop through markers, but create each with a helper function
              var point = new google.maps.LatLng(43.82589,-79.10040);
              var marker = createMarker(point,'Some stuff to display in the<br>Third Info Window')
    
        function createMarker(latlng, html) {
            var contentString = html;
            var marker = new google.maps.Marker({
                position: latlng,
                map: map,
                zIndex: Math.round(latlng.lat()*-100000)<<5
                });
    
            google.maps.event.addListener(marker, 'click', function() {
                infowindow.setContent(contentString); 
                infowindow.open(map,marker);
                });
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Google Maps API v3 , and have several map markers that
i have several markers on the google map displayed in android, i wish to
I have a google map with markers on several states. The markers are trucks,
I need to display a google map with several markers. The problem I have
I have several questions regarding the Google Map V3 API and its library for
I have found location on google map and get custom iframe code with marked
I have several markers on one map, I also have several links and I
I have to create several markers on Google Maps, in run-time. Their initial position
I have a map on a page which displays several places with markers and
I have a Google Map involving several different arrays of data, and I'm having

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.