GoogleMap API events click to zoom

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?

Answers


Your value for zoom is constant,that is why:

map.setZoom(8/*constant*/);

You need to make it dynamic, something like:

map.setZoom( map.getZoom() + 2);

Need Your Help

Issues with Rails3.0 vs Rails 3.1

ruby-on-rails-3 ruby-on-rails-3.1 rvm rails-3-upgrade

So I finally upgraded (and then downgraded because of Unity) Ubuntu and reinstalled RVM but I'b stuck with rails 3.1 now, which is fine but all my old projects are in rails 3.0 and 3.1 has some