Search code examples
javascriptruby-on-railsgoogle-mapsmarkergmaps4rails

How to rotate marker in rails using gmaps4rails?


I have set car as a marker and want to rotate it. Is there any way to rotate it in the defined code. If not, what other options do I have?

handler = Gmaps.build('Google');
handler.buildMap({
    provider: {},
    internal: {
        id: "map"
    }
}, function() {
    marker = handler.addMarkers([{
        lat: lat,
        lng: lng,
        "picture": {
            "url": "/assets/car.png",
            "width": 17,
            "height": 38
        }
    }]);
});

Solution

  • I have used the solution from this answer. It uses the canvas to rotate the image. See the jsfiddle link for live example at the end of the answer.