Googleマップにリスナーidle
を追加しようとしています。リスナーの追加時にGoogleマップV3の地図が読み込まれない
問題:以下に示すように、私はリスナーを追加すると、私はエラーを取得するCannot read property '__e3_' of undefined
JSコード
google.maps.event.addListener(map, 'idle', function() {
console.log('hello');
}
私は確信してマップを作るために、setTimeout(..., 1000)
を追加することによってそれを解決1秒後にロードされます。
質問:
- が原因ロードされていないマップに誤りですか?
- これを解決する最善の方法ですか?
- この問題は発生するはずですか?私は他のコードなしでこの同じリスナーをマップに追加するとこのエラーはポップアップしないだろうと推測しています。地図
の<script type="text/javascript"> var map; var geocoder; var directionsService = new google.maps.DirectionsService(); function initialize() { var center_latlng = new google.maps.LatLng(42.354183,-71.065063); var options = { zoom: 15, minZoom: 11, maxZoom: 19, center: center_latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map(document.getElementById("map_canvas"), options); var Style = [ { featureType: "poi", elementType: "labels", stylers: [ { visibility: "off" } ] },{ featureType: "landscape", elementType: "labels", stylers: [ { visibility: "off" } ] } ] map.setOptions({styles: Style}); geocoder = new google.maps.Geocoder(); // Marker Clusterer var styles = {styles: [{ height: 34, url: "images/template/markers/cluster.png", width: 34, textColor: '#FFF', textSize: 12 }, { height: 56, url: "http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/images/m2.png", width: 56 }, { height: 66, url: "http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/images/m3.png", width: 66 }, { height: 78, url: "http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/images/m4.png", width: 78 }, { height: 90, url: "http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/images/m5.png", width: 90 }] }; var mcOptions = {gridSize: 50, maxZoom: 15, styles: styles['styles']}; mc = new MarkerClusterer(map, [], mcOptions); } </script>
EDIT
初期
あなたは、いくつかのコンテキストを提供することができますか?いつ、いつ、どのように地図を初期化しますか? –
@NiklasRingdahlコードを更新しました。見てください:) – Nyxynyx