1

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.Marker({
    position: latlng,
    map: this.map
});

marker.setIcon({
  url:"assets/icon/nav.png",
  //path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
  scale: 1,
  rotation: heading,
  scaledSize: new google.maps.Size(35, 35),
});

The rotation attribute is working with google.maps.SymbolPath.XXXX as the line commented in the code but not with a custom Icon Image like I wrote in my code,

So I'm asking is there any solution to make custom icon image rotate ? Or to create a google.maps.SymbolPath from an image ?

MrUpsidown
  • 21,592
  • 15
  • 77
  • 131
Karim Garali
  • 75
  • 2
  • 13
  • possible duplicate of [rotate a .gif image on google maps api v3?](https://stackoverflow.com/questions/38723573/rotate-a-gif-image-on-google-maps-api-v3) – geocodezip May 20 '21 at 02:52

1 Answers1

7

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
});
MrUpsidown
  • 21,592
  • 15
  • 77
  • 131