1

Is there any way to add an click event with zoom? I am able to perform both individually, but when I use zoom together with a click event it is not working properly.

google.maps.event.trigger(gmarkers[count], "click");
map.setZoom(parseInt(k));

Please refer this jsfiddle: http://jsfiddle.net/Uw9Qy/
An example found here: http://www.geocodezip.com/v3_MW_example_map3_clustered.html

2 Answers 2

3

In your fiddle, you have defined the myClick function (which gets triggered as you click one of the text links), but that function doesn't contain any zoom code.

Try this:

Change the onclick on your <b> tags, add a zoomlevel to it

<b onclick="myclick(0, 11)">Berlin</b>-<b onclick="myclick(1, 8)">Paris</b>-<b onclick="myclick(2, 9)">Rome</b>

Then, add a paramter to your myclick function so you can zoom in:

    this.myclick = function (i, zoomlevel) {
        google.maps.event.trigger(gmarkers[i], 'click');
        map.setZoom(zoomlevel);
    };
Sign up to request clarification or add additional context in comments.

1 Comment

@Ammu you have not told us you want clusters, you linked an example that uses clusters, yes, but your question never states you want clusters. Nevertheless, clusters or not, the principle of my answer still applies. Give us more code, why is this not working? What have you tried.
2
function createMarker() {

            var marker = new google.maps.Marker({
                position: z,
                map: map,
                title: title,
                html: contentstring
            });

            google.maps.event.addListener(marker, 'click', function () {
                map.setCenter(marker.getPosition());
                map.setZoom(10);
                infowindow.setContent(this.html);
                infowindow.open(map, marker);

            });

            //google.maps.event.addListener(marker,'click',function(){
            //window.location.href = marker.url;
            //});   

            gmarkers[ids] = marker;

        };

Specify your desired zoom level in setZoom() :)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.