我试图弄清楚如何添加Google Maps MarkerLabel

我可以显示一个标准标记,但是当我尝试向标记添加!标签时,我得到google.maps.MarkerLabel is not a function

var marker = new google.maps.Marker({
    animation: google.maps.Animation.DROP,
    label: new google.maps.MarkerLabel({
        text: '!'
    }),
    map: myMap,
    position: myMapOptions.center
});

我猜我不能以这种方式实例化一个新的MarkerLabel对象。我应该怎么做才能在标记内得到一个感叹号。

最佳答案

MarkerLabel 匿名对象规范。

var marker = new google.maps.Marker({
    animation: google.maps.Animation.DROP,
    label: {
        text: '!'
    },
    map: myMap,
    position: myMapOptions.center
});
example fiddle
代码段:

var geocoder;
var map;

function initialize() {
  var map = new google.maps.Map(
    document.getElementById("map_canvas"), {
      center: new google.maps.LatLng(37.4419, -122.1419),
      zoom: 13,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });

  var marker = new google.maps.Marker({
    animation: google.maps.Animation.DROP,
    label: {
      text: '!'
    },
    map: map,
    position: map.getCenter()
  });


}
google.maps.event.addDomListener(window, "load", initialize);
html,
body,
#map_canvas {
  height: 100%;
  width: 100%;
  margin: 0px;
  padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script>
<div id="map_canvas"></div>

09-25 17:31