I am new to the Google Maps API v3 and new to Javascript in as well.
I was reading the documentation / guide from the google website about the basics of google maps and in the initialize function, I saw this snippet of code
google.maps.event.addListener(marker, 'click', function() {
map.setZoom(8);
map.setCenter(marker.getPosition());
});
And thus, when I ran this code, it created a click function that zoomed in when you click the marker. However, this click feature only works once. By this, I mean you can only click the marker once and it will zoom in one time.
I am trying to figure out how to enable the marker to be clicked multiple times and zoomed multiple times. I created a variable for setZoom, but I still don’t know how to enable the marker to be clicked multiple times. I have tried looping this event as well copying and pasting the snippet to have the same code twice. None of these options have worked.
Perhaps it is due to my inexperience to javascript that I am unable to figure out such an easy task. What direction should I look towards in order to create the feature I want?
Your value for
zoomis constant,that is why:You need to make it dynamic, something like: