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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With