2011-09-29 5 views
0

다른 스크립트에서 Google지도를 참조하려면 어떻게해야합니까? 내 WordPress 페이지에서 내지도를 빌드하는 javascript (a) 및 jQuery 스크립트 (b)를로드합니다. 지도에 대한 참조를 스크립트 (b)로 전달하는 방법을 찾아야합니다. 문제는지도가 스크립트 (a)의 함수 안에 만들어 졌다는 것입니다. 스크립트에서다른 스크립트에서 Google지도를 참조하려면 어떻게해야합니까?

는 (a)에, 내가있어 :

스크립트에서
function map_maker_js(args) { 
var map = new google.maps.Map(document.getElementById(args['id']), myOptions); 

//code for building map continues 
} 

(B) :

나는이 유래 solution을 보았다
jQuery.noConflict(); 

jQuery(document).ready(function($) { 

//say I need the map's bounds 
//how can I access map, in order for this to work: 
map.getBounds(); 

} 

,하지만 난 그게 작동시킬 수 없습니다 .

답변

1

글로벌 네임 스페이스에 고정하십시오.

function map_maker_js(args) { 
    window.map = new google.maps.Map(
      document.getElementById(args['id']), myOptions); 

    //code for building map continues 
} 

JQuery와

jQuery.noConflict(); 

jQuery(document).ready(function($) { 
    window.map.getBounds(); 
} 

하지만 먼저 실행 map_maker_js 완료해야합니다.

+0

메시지 주셔서 감사합니다. map_maker_js가 먼저 실행되도록하려면 어떻게해야합니까? 현재 jQuery가 동시에로드되고 있습니다. 어떤 제안? 고맙습니다. – Laxmidi

+0

jquery'ready' 콜백에서'map_maker_js'를 호출하십시오. –

관련 문제