Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rotate marker icon image in Google Maps Javascript API v3 [duplicate]

I am trying to rotate marker icon image but rotation angle doesn't seem to have any effect on the orientation of the icon image.

I found that giving svg path instead of image for marker would make the rotation work like intended.

But is there any way to make rotation work when using image?

jsfiddle of the issue

function updateMap(bearing) {
// var bearing = 135;

console.log(bearing);
var icon = marker.getIcon();
icon.rotation = bearing;
marker.setIcon(icon);

console.log(marker);
}
function initialize() {
   initMap({ Latitude:37.4419, Longitude: -122.1419});
}
like image 811
devN Avatar asked Sep 16 '25 17:09

devN


1 Answers

You can't do this when you provide a URL for the image like that.

From the docs:

" If a string is provided, it is treated as though it were an Icon with the string as url."

And the Icon class hasn't got a rotate method. Only Symbol lets you do this.

like image 93
duncan Avatar answered Sep 18 '25 08:09

duncan