javascript 旋转谷歌地图标记图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16211242/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 03:43:44  来源:igfitidea点击:

Rotate google map marker image

javascriptgoogle-maps

提问by wild

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

我正在使用上面的代码,这很好,但它通过路径代码显示 FORWARD_OPEN_ARROW :google.maps.SymbolPath.FORWARD_OPEN_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

例如汽车图像,因此当车辆向某个方向移动时它可以旋转。我有一定的旋转度,所以有什么方法可以放置图像而不是 arraow

采纳答案by Satish Sharma

try this

试试这个

marker1 = new google.maps.Marker( 
{
    position: myLatlng,
            map: map,
            icon: { 
                    url: "/path/to/your/image.jpg",
                    scale: 2,
                    rotation: degree   
                    }


        });

回答by duncan

You're using a Symbolobject for your icon in that example. Instead you can use an Iconobject.

在该示例中,您正在为图标使用Symbol对象。相反,您可以使用Icon对象。

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.

但是,它不包括旋转属性。相反,我假设您有多个精灵,因此您可以根据需要更新该 URL 以使用特定图像来表示不同程度的旋转。例如,您可以将它们命名为“image0.jpg”、“image45.jpg”和“image90.jpg”等。

Alternatively you could continue to use the Symbol object, but you can specify a path using SVG path notation.

或者,您可以继续使用 Symbol 对象,但您可以使用SVG path notation指定路径