Google Maps API : Rotation with a custom marker Icon

前端 未结 1 1264
故里飘歌
故里飘歌 2021-01-27 18:09

I\'m working with Google Map Javascript API and I\'m trying to create a custom Marker with a custom Icon which works with rotation,

var marker = new google.maps.         


        
相关标签:
1条回答
  • 2021-01-27 18:32

    1) No, as the Icon object doesn't have a rotation property, and

    2) yes, you can, but for this, you need to use a Symbol object and the SVG path notation. You can check this answer and this example for more info.

    var symbol = {  
        path: "M0 0 H 90 V 90 H 0 L 0 0",
        fillColor: '#FF0000',
        fillOpacity: .5,
        anchor: new google.maps.Point(0, 0),
        strokeWeight: 0,
        scale: .5,
        rotation: 45
    }
    
    var marker = new google.maps.Marker({
        position: new google.maps.LatLng(0, 0),
        map: map,
        icon: symbol
    });
    
    0 讨论(0)
提交回复
热议问题