Google Maps API : Rotation with a custom marker Icon

ⅰ亾dé卋堺 提交于 2020-04-17 19:30:19

问题


I'm working with Google Map Javascript API and I'm trying to create a custom Marker with a custom Icon which works with rotation,

var marker = new google.maps.Marker({
    position: latlng,
    map: this.map
});

marker.setIcon({
  url:"assets/icon/nav.png",
  //path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
  scale: 1,
  rotation: heading,
  scaledSize: new google.maps.Size(35, 35),
});

The rotation attribute is working with google.maps.SymbolPath.XXXX as the line commented in the code but not with a custom Icon Image like I wrote in my code,

So I'm asking is there any solution to make custom icon image rotate ? Or to create a google.maps.SymbolPath from an image ?


回答1:


1) No, as the Icon object doesn't have a rotation property, and

2) yes, you can, but for this, you need to use a Symbol object and the SVG path notation. You can check this answer and this example for more info.

var symbol = {  
    path: "M0 0 H 90 V 90 H 0 L 0 0",
    fillColor: '#FF0000',
    fillOpacity: .5,
    anchor: new google.maps.Point(0, 0),
    strokeWeight: 0,
    scale: .5,
    rotation: 45
}

var marker = new google.maps.Marker({
    position: new google.maps.LatLng(0, 0),
    map: map,
    icon: symbol
});


来源:https://stackoverflow.com/questions/49595076/google-maps-api-rotation-with-a-custom-marker-icon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!