2014-04-21 1 views
1

외부 Google 자바 스크립트 파일에 내 Google지도 자바 스크립트를 넣어야하고 이에 대한 일부 문제가 있습니다. 아래 코드는 작업중인 HTML 파일에서 가져온 것으로, 스크립트 src 태그 및 DomListener를 포함하여 외부 파일에 함수를 복사하려고 시도했습니다. 내가 겪고있는 문제는 DomListener에 있으며 매개 변수를 제대로로드 할 수 없습니다. 외부 파일에 넣어야 할 내용과 스크립트를 실행하기 위해 HTML 파일을 호출해야하는 부분을 도와 주실 수 있는지 궁금합니다. 외부 파일에 Google지도 자바 스크립트 기능 넣기

나를 위해 잘 작동, 매우 앤서니

<!DOCTYPE html> 
<html> 
<head> 
<link href="mystyle.css" rel="stylesheet" type="text/css" /> 
<meta name="Park Map Brisbane" 
    content="initial-scale=1.0, user-scalable=no"> 
<meta charset="utf-8"> 
<title>Info windows</title> 
<style> 
#map-canvas { 
    height: 800px; 
    width: 800px; 
    text-align: center; 
    margin-left: 51px; 
    margin: 0px; 
    padding: 0px 
} 

.gm-style-iw { 
    height: 100% !important; 
    overflow: hidden !important; 
} 
</style> 
<script 
    src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script> 
<script> 
    function initialize() { 
     var myLatlng1 = new google.maps.LatLng(-25.363882, 150.044922); 
     var myLatlng2 = new google.maps.LatLng(-25.363882, 152.044922); 
     var mapOptions = { 
      zoom : 6, 
      center : myLatlng1 
     }; 

     var map = new google.maps.Map(document.getElementById('map-canvas'), 
       mapOptions); 

     var contentString1 = 'Mott Park' 
     var contentString2 = 'Kilpa Park' 

     var infowindow = new google.maps.InfoWindow({}); 

     var marker1 = new google.maps.Marker({ 
      position : myLatlng1, 
      map : map, 
      title : 'Park' 
     }); 
     var marker2 = new google.maps.Marker({ 
      position : myLatlng2, 
      map : map, 
      title : 'Water' 
     }); 
     google.maps.event.addListener(marker1, 'click', function initialize() { 
      infowindow.close();//hide the infowindow 
      infowindow.setContent(contentString1);//update the content for this marker 
      infowindow.open(map, marker1); 

     }); 
     google.maps.event.addListener(marker2, 'click', function initialize() { 
      infowindow.close();//hide the infowindow 
      infowindow.setContent(contentString2);//update the content for this marker 
      infowindow.open(map, marker2); 
     }); 
    } 

    google.maps.event.addDomListener(window, 'load', initialize); 
</script> 
</head> 
<body> 
    <div id="map-canvas"></div> 
</body> 
</html> 

답변

2

그것을 주셔서 감사합니다.

여기 내보기/HTML 파일

<html> 
<head> 
    <link href="mystyle.css" rel="stylesheet" type="text/css"/> 
    <meta name="Park Map Brisbane" content="initial-scale=1.0, user-scalable=no"> 
    <meta charset="utf-8"> 
    <title>Info windows</title> 
     <style> 
     #map-canvas { 
     height: 800px; 
     width: 800px; 
     text-align: center; 
     margin-left: 51px; 
     margin: 0px; 
     padding: 0px 
     } 
     .gm-style-iw{ 
     height: 100% !important; 
     overflow: hidden !important; 
     </style> 
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script> 
    <script src="/assets/scripts/test.js"></script>  
    </head> 
    <body> 
    <div id="map-canvas"></div> 
    </body> 
<html> 

스크립트 부분은 내가 '/ 자산/스크립트'파일 경로를 필요로 내 자바 스크립트 파일에 액세스하려면 외부 파일 내에서 호출 test.js

을 넣어이다. 스크립트가있는 곳에 파일 경로를 입력하십시오. 예를 들어, test.js가 동일한 폴더 레벨에 있으면 test.js 만됩니다.

+0

대단히 감사합니다. –

+0

당신을 환영합니다! :) –

+0

:) 내 관심사에 다른 문제가 있습니다. 어떻게 해결할 지 알고있을 것 같습니까? 나는 그것이 간단하다는 것을 압니다! 고마워 :) [이것은 내 질문이다] (http://stackoverflow.com/questions/23235127/google-maps-domlistener-causing-error-after-going-to-different-page) –

관련 문제