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