Google지도를로드하는 phonegap 응용 프로그램을 개발 중입니다. 아래의 두 가지 자바 스크립트를 사용하여 Google지도를 만듭니다. 다른 자바 스크립트가 서버에서로드되는 동안 하나의 자바 스크립트가 로컬에서로드됩니다.phonegap - 동적으로 자바 스크립트 추가
var script = document.createElement('script');
script.src = 'http://maps.google.com/maps/api/js?sensor=true';
script.type = 'text/javascript';
document.head.appendChild(script);
script.onload = function() {
var script1 = document.createElement('script');
script1.src = 'js/jquery.ui.map.js';
script1.type = 'text/javascript';
document.head.appendChild(script1);
script1.onload = function() {
alert(google.maps.LatLng);
}
};
HTML 페이지가로드 된 후에 두 가지 JavaScript가 모두로드되어야합니다. 코드 아래에서 시도하고 다양한 블로그를 추천했지만 작동하지 않습니다.
동일한 스크립트가 HTML 페이지의 헤더 태그로 작성된 경우 완벽하게 작동합니다. 하지만 내 응용 프로그램에서 동적으로로드해야합니다.
도와주세요
....는 해결 :는 var doc_write = document.write; // Remember original method; document.write = function(s) {$(s).appendTo('body')}; $.getScript(' http://maps.google.com/maps/api/js?sensor=true ').done(function() { $.getScript('js/jquery.ui.map.js').done(function() { document.write = doc_write; // Restore method setTimeout(function() { alert(google.maps.LatLng); },1000); }) .fail(function(jqxhr, settings, exception) { alert(exception); // this gets shown document.write = doc_write; // Restore method }); }).fail(function() { alert('failed to load google maps'); });
문제 : 이 초기화하려면 어느 정도 시간이 소요됩니다.
jQuery에 태그를 추가 했으므로 [$ .getScript()] (https://api.jquery.com/jQuery.getScript/) – Satpal
와 비슷한 종류의 문제를 사용할 수 있습니다 .i recaptcha를 구현해야합니다. phonegap.but phonegap 요청을 'file : //'에 전달하여 오류 발생 –
@Satpal 또한 $ .getScript로 시도했지만 동일한 문제가 발생했습니다. –