예 - Earth API를 Maps v3 API와 통합 할 수 있습니다. 여기에 working example이 있습니다. 지구 API는 google.load("earth", "1");
에 비동기 호출을 통해로드가 완료되기 전에 당신이 그렇게 시도하고 그것을 사용할 때 google.earth
가 null 것을 의미한다이 호출을하고 있습니다 -
코드의 문제는 줄 var ge = new GoogleEarth(map);
입니다 Uncaught google.earth not loaded
오류가 발생합니다.
API를로드 한 후에 만 수정해야하는 경우 new GoogleEarth(map)
으로 전화해야합니다. 가장 쉬운 방법은 콜백을 사용하는 것입니다.
예를 들어, script.js
을 다음과 같이 수정할 수 있습니다.
(function(window, google, mapster) {
google.load("earth", "1");
// map options
var options = mapster.MAP_OPTIONS,
element = document.getElementById('map-canvas'),
map = mapster.create(element, options);
// callback method to fire once the api had loaded
google.maps.event.addDomListener(window, 'load', function() { new GoogleEarth(map) });
var marker2 = map.addMarker({
lat: 37.781350,
lng: -122.485883,
draggable: true,
events: [{
name: 'click',
callback: function(e, marker) {
console.log(e, marker);
}
}, {
name: 'dragend',
callback: function() {
alert('dragged');
}
}]
});
// no point calling this here as google.earth will be null
//var ge = new GoogleEarth(map);
}(window, google, window.Mapster));
콜백을 사용할 때 오류가 발생했습니다 ('잡히지 않은 TypeError : 정의되지 않은 함수가 아닙니다'). 그러나 나는 완벽하게 작동하는 실례의 근원을 보았다. 아마도 익명 함수를 호출하는 내부에서'google.load'를 사용하는 것이있을 수 있습니다. 도와 주셔서 감사 드리며 작업 샘플을 보내주십시오! – yulie
이상하게 - 코드를 테스트 한 결과 작동했습니다. 아무래도 도와 줘서 기뻐. 올바른 사람이 답을 표시하면 나중에도 도움을 줄 수 있습니다. – Fraser
아 - 알았어. 코드를 붙여 넣을 때 처음 두 문장이 뒤에서 앞으로 나왔다. – Fraser