Google Maps API V3 change Marker Option

2019-07-26 01:30发布

问题:

marker = new google.maps.Marker({
    icon: image,
    position: new google.maps.LatLng(locations[i][1], locations[i][2]),
    flat: true,
    optimized: false,
    map: map,
    visible: true,
    customInfo: locations[i][0]
    });

I have the above to build my Marker in my Google Map but when the marker is clicked, the map zooms to the location and I'd like to make the marker non clickable.

I have tried the following with no success

google.maps.event.addListener(marker, 'click', function() {
    map.setZoom(17);
    map.setCenter(this.getPosition());
    marker.MarkerOptions ({
        clickable: false
    });
});

回答1:

Read the documentation - the name of the method you are looking for is called setOptions

marker.setOptions({clickable:false});


回答2:

I found it and its actually quite a simple way of doing it.

marker.setClickable (true);