2015-09-20 4 views
5

Ich versuche herauszufinden, wie Sie eine Google Maps MarkerLabel hinzufügen.Google Maps MarkerLabel ist keine Funktion

Ich bin in der Lage, eine Standardmarkierung anzuzeigen, aber wenn ich versuche, eine !-Beschriftung zu der Markierung hinzuzufügen, bekomme ich 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 
}); 

Ich schätze, ich kann ein neues MarkerLabel-Objekt auf diese Weise nicht instanziieren. Was soll ich tun, um ein Ausrufezeichen innerhalb der Markierung zu erhalten.

+0

Warum die unten Abstimmung? – Quantastical

Antwort

9

MarkerLabel ist ein anonymes Objekt Spezifikation.

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

example fiddle

Code-Schnipsel:

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>

+0

Vielen Dank. Ich frage mich, warum das ein anonymer Gegenstand ist, wo alles andere nicht ist. – Quantastical

+1

'MapOptions',' MarkerOptions', 'Icon', ... sind alle anonyme Objekte. – geocodezip