如何在Google地图中旋转标记?

sms*_*247 20 google-maps

以下是旋转标记的代码,但是如何旋转自定义标记.任何的想法?

var angleDegrees = 150;
new google.maps.Marker({
    position: a,
    map: map,
    icon: {
        path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
        scale: 6,
        fillColor: "red",
        fillOpacity: 0.8,
        strokeWeight: 2,
        rotation: angleDegrees //this is how to rotate the pointer
    }  
});
Run Code Online (Sandbox Code Playgroud)

小智 23

在API中可以使用旋转. https://developers.google.com/maps/documentation/javascript/examples/overlay-symbol-custom

var icon = {
    ...
    path: '...',
    scale: 1,
    rotation: [degrees]
};

marker = new google.maps.Marker({
  map: [...],
  icon: icon,
  ...
});
Run Code Online (Sandbox Code Playgroud)

  • 仅适用于SVG格式的自定义符号,因此具有路径 (4认同)

Kar*_*ren 4

API参考没有具体说明如何完成旋转,但由于path采用 SVG 元素,我想说这就是他们设法旋转它的方式。如果您使用 SVG 创建自定义标记,则可以使用transform="rotate(deg centerX centerY").