marker1 = new google.maps.Marker(
{
position: myLatlng,
map: map,
icon: {
path: google.maps.SymbolPath.FORWARD_OPEN_ARROW,
scale: 2,
rotation: degree
}
});
I am trying to rotate marker image on google map in some degree.
i am using above code it is nice but it is showing FORWARD_OPEN_ARROW by the code of path: google.maps.SymbolPath.FORWARD_OPEN_ARROW, but i want add a image here instead of arrow
such as car image so it can be rotate when vehicle move in some direction. i have a degree of rotation so is there any way to put image instead of arraow
If you create your custom marker using SVG it can be done quite easily using transform="rotate(deg centerX centerY") .
The transition() and moveMarker() are used to move marker smoothly on click on the Google map.
You're using a Symbol object for your icon in that example. Instead you can use an Icon object.
icon: {
url: "/path/to/your/image.jpg"
}
It doesn't include a rotation attribute however. Instead I'd assume you'd have multiple sprites, so you update that URL to use a particular image to represent different degrees of rotation, as required. e.g. you could have them named like "image0.jpg", "image45.jpg" and "image90.jpg", etc.
Alternatively you could continue to use the Symbol object, but you can specify a path using SVG path notation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With