Google Maps API v3: How do I dynamically change the marker icon?

前端 未结 5 1948
心在旅途
心在旅途 2020-11-30 20:33

Using Google Maps API v3, how do I programmatically change the marker icon?

What I would like to do is, when someone hovers over a link - to have the corresponding m

5条回答
  •  独厮守ぢ
    2020-11-30 20:59

    You can also use a circle as a marker icon, for example:

    var oMarker = new google.maps.Marker({
        position: latLng,
        sName: "Marker Name",
        map: map,
        icon: {
            path: google.maps.SymbolPath.CIRCLE,
            scale: 8.5,
            fillColor: "#F00",
            fillOpacity: 0.4,
            strokeWeight: 0.4
        },
    });
    

    and then, if you want to change the marker dynamically (like on mouseover), you can, for example:

    oMarker.setIcon({
                path: google.maps.SymbolPath.CIRCLE,
                scale: 10,
                fillColor: "#00F",
                fillOpacity: 0.8,
                strokeWeight: 1
            })
    

提交回复
热议问题