Google Maps MarkerLabel不是一个功能

时间:2015-09-20 14:50:11

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

我正在试图找出如何添加JSFiddle

我可以显示一个标准标记,但是当我尝试向标记添加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 });

{{1}}

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

1 个答案:

答案 0 :(得分:12)

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"></script>
<div id="map_canvas"></div>
&#13;
&#13;
&#13;