简体   繁体   中英

Trigger Google map click event with zoom javascript

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

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);
    };
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() :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM