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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:53:23+00:00 2026-06-07T19:53:23+00:00

I have functions that when a li element is clicked markers are added to

  • 0

I have functions that when a li element is clicked markers are added to the map. If another li is clicked then the original markers are removed and the new one appearr.

The issue I am having is that the markers are placed on the map when a li is clicked for the first time. When a second li is clicked the markers are removed but the new ones are not added. I get no error in firebug. I cant see what I am missing.

$(document).ready(function() {

    $(".markerSelection").click(function() {
      var selectionId = $(this).attr("id");
      drop(selectionId);
    }); 
});



var markers = {
    shopping : [
    new google.maps.LatLng(52.26183, -7.11339),
    new google.maps.LatLng(52.26134, -7.11226),
    new google.maps.LatLng(52.26067, -7.11181),
    new google.maps.LatLng(52.26003, -7.11033)],
    cars : [
    new google.maps.LatLng(52.26183, -7.11339),
    new google.maps.LatLng(52.26134, -7.11226),
    new google.maps.LatLng(52.26067, -7.11181),
    new google.maps.LatLng(52.26003, -7.11033)] 
};

var iterator = 0; 

function drop(selectionId) {
    clearOverlays();
    for (var i = 0; i < markers[selectionId].length; i++) {
    setTimeout(function() {
    addMarker(selectionId);
    }, i * 200);
    }
}

function addMarker(selectionId) {
    marker = new google.maps.Marker({
    position: markers[selectionId][iterator],
    map: map,
    draggable: false,
    animation: google.maps.Animation.DROP
    });
    iterator++;
    markersArray.push(marker);
}

// Removes the overlays from the map, but keeps them in the array
function clearOverlays() {
  if (markersArray) {
    for (i in markersArray) {
      markersArray[i].setMap(null);
    }
  }
}
  • 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-07T19:53:26+00:00Added an answer on June 7, 2026 at 7:53 pm

    I reviewed your code one more time, and I think the problem is with iterator, which is initialized to 0 in global scope. That is why the first time it works okay, but after that, indices exceed. It seems you should set it to zero at the beginning of the drop() function.
    However it makes more sense if you pass index as a second parameter of addMarker() instead of an outer variable which is handled in drop() and complicate you code.

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

Sidebar

Related Questions

I have some functions that are triggered when an element is clicked. The elements
I have two functions: one that creates a new <textarea> when a button is
So right now I have a simple canvas element with functions that create random
I have this function that switches the HTML contents from one element on a
I have an element within another element and both have separate click functions. What
Hi I have a function that makes ajax calls once an element is clicked.
I have written some JavaScript that opens an element when an element is clicked.
I have a function that is being called when a particular element is clicked
I want to have it so that clicking one element affects a different one,
I have a jQuery function that flips an element and then turn it back

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.