Google Maps SVG image marker icons not showing in IE11

前端 未结 4 889
自闭症患者
自闭症患者 2021-02-09 10:11

There is an issue on a site I have been working on that for some reason the SVG image markers are not showing up in IE 11.

I have two sets of markers:

  • the
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-09 10:57

    It seems that Google Maps doesn't really support using SVG images for markers at the moment. This fact is easy to overlook, because it turns out that SVG marker images do actually work in, eg. Chrome and Opera.

    However, the Google Maps API (v3) specifically provides Symbol objects for displaying vector paths in map markers. I found that specifying the vector image in SVG path notation allowed it to work in IE and other browsers.

    Example (from Google Maps docs, here):

    var goldStar = {
      path: 'M 125,5 155,90 245,90 175,145 200,230 125,180 50,230 75,145 5,90 95,90 z',
      fillColor: 'yellow',
      fillOpacity: 0.8,
      scale: 1,
      strokeColor: 'gold',
      strokeWeight: 14
    };
    
    var marker = new google.maps.Marker({
      position: map.getCenter(),
      icon: goldStar,
      map: map
    });
    

    (Thanks to this answer too)

提交回复
热议问题