Can someone tell me why I can't see the marker on this map?
<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>
Look in your browser's error console:
You need to expose that variable, since
map
is not currently visible outside of the scope ofinitialize()
. Or, move the marker code intoinitialize()
: