2015-09-20 10 views
5

私はGoogle Maps MarkerLabelを追加する方法を理解しようとしています。Googleマップ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オブジェクトをインスタンス化できないと思います。感嘆符を得るために私は何をするべきですのマーカー。

+0

なぜダウン投票? – Quantastical

答えて

9

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>

+0

よろしくお願いいたします。私はなぜそれが他のものではない匿名のオブジェクトであるのだろうと思う。 – Quantastical

+1

'MapOptions'、' MarkerOptions'、 'Icon'、...はすべて匿名オブジェクトです。 – geocodezip

関連する問題