Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps MarkerLabel is not a function

I'm trying to figure out how to add a Google Maps MarkerLabel.

I'm able to get a standard marker to display, but when I try to add a ! label to the marker, I get 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
});

I'm guessing I can't instantiate a new MarkerLabel object this way. What am I supposed to do to get an exclamation point inside the marker.

like image 477
Jeff Jenkins Avatar asked Sep 20 '15 14:09

Jeff Jenkins


1 Answers

MarkerLabel is an anonymous object specification.

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

example fiddle

code snippet:

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>
like image 167
geocodezip Avatar answered Nov 06 '22 09:11

geocodezip