2014-12-10 9 views
1

내가 Google지도 v3으로 구글 어스를 추가하려면이하고 있어요로드되지 Uncaught google.earth not loaded 내가 뭘 잘못했는지 잘 모르겠다. http://maps.google.com 가인가 : http://plnkr.co/edit/NlPF3F259IIMgj2pfN09?p=previewcatch되지 않은 google.earth은

난 정말 Google지도는 여기에서 하나를 좋아하는 구글 어스를 추가 할 : 여기 내 전체 코드가 도움이 경우

http://google-maps-utility-library-v3.googlecode.com/svn/trunk/googleearth/docs/reference.html :

나는이 참조를 사용하고 있습니다 v3에서 가능합니까?

답변

1

예 - 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)); 
+0

콜백을 사용할 때 오류가 발생했습니다 ('잡히지 않은 TypeError : 정의되지 않은 함수가 아닙니다'). 그러나 나는 완벽하게 작동하는 실례의 근원을 보았다. 아마도 익명 함수를 호출하는 내부에서'google.load'를 사용하는 것이있을 수 있습니다. 도와 주셔서 감사 드리며 작업 샘플을 보내주십시오! – yulie

+1

이상하게 - 코드를 테스트 한 결과 작동했습니다. 아무래도 도와 ​​줘서 기뻐. 올바른 사람이 답을 표시하면 나중에도 도움을 줄 수 있습니다. – Fraser

+0

아 - 알았어. 코드를 붙여 넣을 때 처음 두 문장이 뒤에서 앞으로 나왔다. – Fraser