2012-09-11 4 views
0

이지도에서 마커를 볼 수없는 이유를 누군가 말해 줄 수 있습니까? 브라우저의 오류 콘솔에서Google 마커가 표시되지 않음

<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> 
<style type="text/css"> 
    html { height: 100% } 
    body { height: 100%; margin: 0; padding: 0 } 
    #map_canvas { height: 100% } 
</style> 

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?keykey=AIzaSyBG47z_ebM8I6Ic2-rXL8QiPN5CHCOBwco&sensor=true"></script> 
<script type="text/javascript"> 
    function initialize() { 
     var mapOptions = { 
      center: new google.maps.LatLng(37.998727,-0.686259), 
      zoom: 18, 
      minZoom: 4, 
      maxZoom: 13, 
      mapTypeId: google.maps.MapTypeId.ROADMAP, 
      streetViewControl: false 
     }; 
     var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); 
    }  

    var marker = new google.maps.Marker({ 
     position: new google.maps.LatLng(37.998727,-0.686259), 
     map: map 
    }); 
</script> 
<body onload="initialize()"> 
<div id="map_canvas" style="width:600px; height:600px;"></div> 
+1

Enter 키가 깨져 있습니까? ': /' –

답변

1

봐 : map 현재 initialize()의 범위를 외부에 표시되지 않기 때문에

Uncaught ReferenceError: map is not defined 

당신은, 그 변수를 노출 할 필요가있다. 또는 마커 코드를 initialize()으로 이동하십시오.

function initialize() { 
    var mapOptions = { 
     center: new google.maps.LatLng(37.998727,-0.686259), 
     zoom: 18, 
     minZoom: 4, 
     maxZoom: 13, 
     mapTypeId: google.maps.MapTypeId.ROADMAP, 
     streetViewControl: false 
    }; 
    var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); 

    var marker = new google.maps.Marker({ 
     position: new google.maps.LatLng(37.998727,-0.686259), 
     map: map 
    }); 
}  
+0

고마워, 좀 더 정교하게 만들어 줄 수 있니? 아주 새롭고 올바르게 만들 수 없어! –

+0

그냥 내 대답에있는 초기화 함수를 바꿉니다. –

+0

정말 고마워요! 더블 엑스 –

관련 문제