자바 스크립트에 새 설명이 포함되어 있습니다. 마커 목록 (파이썬에서)을 Google지도에 추가하려고합니다. 잡히지 않은 참조 오류 : 정의되지 않음
내 원시 Jinja2 템플릿 :<head>
<title>Google Map Test</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
#map-canvas { height: 700px; width: 400px; }
</style>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=MY_API_KEY&sensor=false">
</script>
<script type="text/javascript">
var locations = {{ locations|safe }};
/*
locations|safe results in the following line in my rendered template:
var locations = [['A.W. Hastings/Windows & Doors by Brownell', '44.4456', '-73.1276'], ['AARP', '44.4757', '-73.2113'], ['Adirondack Audiology', '44.4792', '-73.22'], ['Alchemy Jewelry Arts #1A', '44.4672', '-73.2147'], ['All Smiles Dental', '44.2334', '-72.5539']];
*/
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(43.953, -72.593),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);
}
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (var i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
</script>
목록은 정기적으로 변경하기 때문에 내보기에서 목록 "위치"를 보냅니다.
위치 변수를 정의한 행에 대해 [캐치 오류]가 표시됩니다. 전체 출력은 다음
catch되지 ReferenceError가 : 없음 127.0.0.1:14가 (익명 함수)
오류 메시지를 생성하기 위해 선언되지 않은 식별자 '없음'을 참조하는 코드가 있어야하지만 여기에는 표시되지 않습니다. –
@DaggNabbit 내 템플릿에서 복사하여 붙여 넣습니다. –
* 렌더링 된 템플릿의 출력이 잘리지 않았지만 "없음" –