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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:29:29+00:00 2026-06-13T19:29:29+00:00

I am drawing markers that represent shops on a map. There is a single

  • 0

I am drawing markers that represent shops on a map.

There is a single global infoWindow which appears for each marker that is clicked, right after it closes for the previous clicked marker.

In some cases a few shops may have the same address so the markers appear on top of each other and one can only see the top marker.

To solve this I added pagination to the infoWindow.

The problem is that the top marker is the last one on the list, and so the infoWindow shows the latest shop’s info and the pagination shows the “back” button, instead of showing the first shop first and the “next” button.

I tried reversing the order of the “for” loop like this for (i=limit; i>0; i--) but it doesn’t work. The map gets stuck as if running some ajax request.

Here’s the code:

function drawShopsMarkers(){
    var marker;
    markersArray = [];
    var i;
    var limit = globalShopsArr.length;

    for (i=0; i<limit; i++){
        marker = new google.maps.Marker({
            position: new google.maps.LatLng(globalShopsArr[i].shopLat, globalShopsArr[i].shopLng), 
            map: map,
            title: globalShopsArr[i].shopTitle
        });

        markersArray.push(marker);
        marker.setMap(map);

        google.maps.event.addListener(markersArray[i], 'click', makeListener(i));
    }

    function makeListener(index) {
        return function() {
            globalInfowindow.disableAutoPan=true;
            globalInfowindow.open(map,markersArray[index]);

            CreateInfoWindowString(index);

            globalInfowindow.setOptions({
                content: globalContentString
            });
        }
    }       
}

The CreateInfoWindowString() function simply populates the globalContentString including the pagination.

Can you say what’s causing the problem?

  • 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-13T19:29:30+00:00Added an answer on June 13, 2026 at 7:29 pm

    Try

    for (i=limit-1;i>=0;i--)
    

    like suggested in the comment. You need to change the line when you attach the function to the marker, too. When you push the marker to the array it’s accumulate but you attach function to a non-existent element. Use another variable and increment it in the loop:

    c++

    This line

    google.maps.event.addListener(markersArray[i],.. ... ...

    When you change the loop to decrement i and try markersArray[i] it must give an error because element i isn’t in the array yet. So create a c variable and use it instead like I wrote and change the line to use c instead of i.

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

Sidebar

Related Questions

I'm drawing a series of markers on a map (using v3 of the maps
I have an application that uses the mapview-overlay-manager code to draw map markers on
I am drawing reactangles in a loop based on the parameters that I get
Possible Duplicate: Drawing multiple pixels/rectangles In my code i wrote a method that creates
I'm back with more work on the Google Map that I've been working on.
I'm trying to draw on a map using markers. The problem I'm having is
When drawing large circle onto a Google map, when the circles get really large
i am drawing chart using High Chart JS in my web app in which
I have a large set of google maps api v3 polylines and markers that
I owned complex drawing code with GDI+ which draws something like a chart on

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.