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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:31:10+00:00 2026-05-22T14:31:10+00:00

I have a JSON array of Marker positions being pulled into a Google map

  • 0

I have a JSON array of Marker positions being pulled into a Google map – This works fine.

I also have infoWindows linked to each of those markers – These also work fine.

However, when I click a marker (in any browser), the infoWindow only appears over the last added marker.

Here is a fiddle: http://jsfiddle.net/neuroflux/8WDwn/10/
and here is my loop:

for (var a = 0; a < dealer_markers.length; a++) {
    var tmpLat = dealer_markers[a].lat;
    var tmpLng = dealer_markers[a].lng;
    var tmpName = dealer_markers[a].name;
    var tmpAdr = dealer_markers[a].adr;
    var tmpTel = dealer_markers[a].pc;
    var tmpPc = dealer_markers[a].tel;

    contentString[a] = '<div id="bg"><h2 class="title">'+tmpName+'</h2><h3 class="address">'+tmpAdr+'</h3><h3 class="pc">'+tmpPc+'</h3><h3 class="telephone">'+tmpTel+'</h3></div>';
    var content = contentString[a];

    dealer[a] = new google.maps.LatLng(tmpLat,tmpLng);

    deal = dealer[a];

    marker[a] = new google.maps.Marker({ 
        map:map,
        position: deal,
        icon:'dealer.png',
        title: "|"+new google.maps.LatLng(dealer[a].Ja,dealer[a].Ka)
    });

    lat = marker[a].position.Ja;
    lng = marker[a].position.Ka;

    compositeLatLng = new google.maps.LatLng(lat,lng);
    mark = marker[a];


    google.maps.event.addListener(mark, 'click', function(a) {
        if (mark.infowindow) {
            mark.infowindow.close();
        }

        mark.infowindow = new google.maps.InfoWindow({ 
            content: contentString[marker.indexOf(this)]
        });

        mark.infowindow.open(map,mark);
    });
}
  • 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-22T14:31:11+00:00Added an answer on May 22, 2026 at 2:31 pm

    As I stated in my comment, you can use a closure to work around the problem. Here is the demo. I created a wrapper function that:

    1. creates a marker
    2. optionally attaches an onclick handler

    Inside that handler:

    1. it attaches a blank infoWindow to the map (if necessary)
    2. it hides that window, changes its content and shows it again over the marker (logic borrowed from here)

    function _newGoogleMapsMarker(param) {
        var r = new google.maps.Marker({
            map: param._map,
            position: new google.maps.LatLng(param._lat, param._lng),
            title: param._head
        });
        if (param._data) {
            google.maps.event.addListener(r, 'click', function() {
                // this -> the marker on which the onclick event is being attached
                if (!this.getMap()._infoWindow) {
                    this.getMap()._infoWindow = new google.maps.InfoWindow();
                }
                this.getMap()._infoWindow.close();
                this.getMap()._infoWindow.setContent(param._data);
                this.getMap()._infoWindow.open(this.getMap(), this);
            });
        }
        return r;
    }
    
    
    for (var a = 0; a < dealer_markers.length; a++) {
        .
        .
        .
        var marker = _newGoogleMapsMarker({
            _map: map,
            _lat: tmpLat,
            _lng: tmpLng,
            _head: '|' + new google.maps.LatLng(tmpLat, tmpLng),
            _data: '...'
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JSON array that looks like this: ['Monkey','Cheetah','Elephant','Lizard','Spider'] I also have a
I have a JSON array like this: { forum:[ { id:1, created:2010-03-19 , updated:2010-03-19
I have a json array with the key 'BASIS-TYPE'. If I use this value
I have my json array with is this : [{id:1,cid:1,da:08:00:00,a:12:00:00,data:2011-07-03,persone:3,nome:Via Bligny}, {id:8,cid:1,da:08:30:00,a:14:45:00,data:2011-09-26,persone:2,nome:Via Bligny}, {id:9,cid:1,da:08:30:00,a:14:15:00,data:2011-09-26,persone:2,nome:Via
My problem: I have an JSON Array containing arrays, which i render into the
[I have some code to create a JSON array. In this code I am
I have json array with a value that needs to be populated into an
I have this JSON array // Json array var productList = {products: [ {description:
I have a JSON string array of objects like this. [{id:4,rank:adm,title:title 1}, {id:2,rank:mod,title:title 2},
with reference of this question Sort json array I have the following JSON String

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.