Google地图 - 自定义标记图标显示在默认图标下

时间:2015-08-28 16:34:42

标签: javascript angularjs google-maps google-maps-api-3 maps

我想在地图上添加一个带有自定义图标的标记。

ItemsSource

这样做会在地图上添加新标记,但会在默认图标(红色位置符号)下添加自定义图标。这很奇怪。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

通常,您可以使用以下方法添加自定义图标:

  var image = 'http://i.imgur.com/OG4CZt3.png';
  var beachMarker = new google.maps.Marker({
    position: {lat: -33.890, lng: 151.274},
    map: map,
    icon: image
  });

<小时/> 以下是完整代码段from the docs

&#13;
&#13;
#map {
    height: 250px;
}
&#13;
<div id="map"></div>

<script>
// This example adds a marker to indicate the position of Bondi Beach in Sydney,
// Australia.
function initMap() {
  var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 4,
    center: {lat: -33, lng: 151}
  });

  var image = 'http://i.imgur.com/OG4CZt3.png';
  var beachMarker = new google.maps.Marker({
    position: {lat: -33.890, lng: 151.274},
    map: map,
    icon: image
  });
}
</script>
<script async defer
     src="https://maps.googleapis.com/maps/api/js?signed_in=false&callback=initMap"></script>
&#13;
&#13;
&#13;

这样做可以防止自定义图标显示在默认图标下方。

相关问题