<!DOCTYPE html>
<html lang="en">
<head><meta charset="utf-8" />
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false®ion=vi&language=vi">
</script>
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript">
var map;
</script>
<style type="text/css">
html {
height: 100%;
}
body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width: 100%; height: 100%"></div>
<script type="text/javascript">
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(10.79, 826.694),
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"),
mapOptions);
}
</script>
<script>
alert(map);
</script>
</body>
</html>
我的一些函数需要使用该map
变量,但是,我不断收到抱怨map
变量身份不明的警报。我怎样才能让浏览器记住地图是在上定义的map = new google.maps.Map(document.getElementById("map_canvas"),
mapOptions);
谢谢