1

I have an array called markers. I have a Google Map populated with markers and I want to call a function that selects all array values so I can set all the marker images to original, before setting the new one to highlighted. This is unless there is a google api way of setting all marker images.

 function show(i)
{
   markers[all].setIcon("lib/images/default.png");
   markers[i].setIcon("lib/images/default_h.png");
}   

2 Answers 2

2

Try:

for(var i in markers)
{
   markers[i].setIcon("lib/images/default.png");
}

If your array keys are incremented integers you should do this way instead

var size = markers.length;
for(var i=0; i<size; i++) { ... }
Sign up to request clarification or add additional context in comments.

Comments

1

you can to it with the every function:

   function show(i) {
        markers.every(function(marker) {
            marker.setIcon("lib/images/default.png");
            return true;
        }

        markers[i].setIcon("lib/images/default_h.png");
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.