Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotate google map marker image [duplicate]

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

like image 763
wild Avatar asked Apr 25 '13 09:04

wild


People also ask

How do I rotate a marker on Google Maps?

If you create your custom marker using SVG it can be done quite easily using transform="rotate(deg centerX centerY") .

How do I move a marker smoothly on Google Maps?

The transition() and moveMarker() are used to move marker smoothly on click on the Google map.


1 Answers

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.

like image 196
duncan Avatar answered Nov 15 '22 05:11

duncan