【问题标题】:How can I customise the color, shape and size of a google map marker [duplicate]如何自定义谷歌地图标记的颜色、形状和大小[重复]
【发布时间】:2013-06-03 22:47:08
【问题描述】:

我想要一个圆形标记,它的大小和颜色可以在 javascript 中动态更改。有没有人这样做过,或者可以指出正确的资源?

到目前为止,我得到了:(据此:https://developers.google.com/maps/documentation/javascript/overlays#Icons

//Map setup
    focusLocation = new google.maps.LatLng(51.5, -0.1);
    var mapOptions = {
        zoom: 12,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        center: focusLocation
    };
    map = new google.maps.Map(document.getElementById('map'),mapOptions);

        setMarkers(map);

function setMarkers(map){
    marker = new google.maps.Marker({
        icon: {
          path: google.maps.SymbolPath.CIRCLE,
          scale: 10
        },
        map: map
    });
});

但是图标还是正常的。

【问题讨论】:

  • 你试过检查the documentation吗?您可以将MarkerSymbol 结合使用。
  • 感谢您的帮助。我已经添加了我目前拥有的代码,但我不确定它为什么不起作用。
  • 尝试添加documentation中一个工作示例中的所有属性

标签: javascript google-maps-api-3


【解决方案1】:

您的标记没有位置。这对我有用:

function setMarkers(map){
    marker = new google.maps.Marker({
        icon: {
          path: google.maps.SymbolPath.CIRCLE,
          scale: 10
        },
        position: map.getCenter(),
        map: map
    });
});

working example

【讨论】:

    【解决方案2】:

    您可以使用此处描述的 javascript api 更改标记图标

    https://developers.google.com/maps/documentation/javascript/reference#Marker

    具体调用 SetIcon() 方法。

    【讨论】:

      猜你喜欢
      • 2012-06-12
      • 1970-01-01
      • 2017-12-18
      • 2015-12-15
      • 2017-03-02
      • 2014-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多