我必须从表单值重新初始化谷歌地图。但是我无法在单击按钮时获得表单的值(名为 dynamic_display)。任何人都可以给出一些想法如何做到这一点。地图代码为:
<script>
function initialize(a,b,zoom){
if (!a || !b ||!zoom){
//alert('not done '+ "lat="+a+" lang= " +b+" zoom= "+zoom);
var centerLoc=new google.maps.LatLng( 53.61701054652337,53.37824736488983);
zoom=16;
}
else
{
//alert('done' + "lat="+a+" lang= " +b+" zoom= "+zoom);
var centerLoc=new google.maps.LatLng(a,b);
}
var mapProp = {
center:centerLoc,
zoom:zoom,
//mapTypeId:google.maps.MapTypeId.ROADMAP
mapTypeId:google.maps.MapTypeId.SATELLITE
};
var map=new google.maps.Map(document.getElementById("googleMap") ,mapProp);
marker=new google.maps.Marker({
position:centerLoc,
title:'Click to zoom'
});
google.maps.event.addListener(marker,'click',function() {
map.setZoom(map.getZoom()+1);
map.setCenter(marker.getPosition());
});
marker.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
形式:
<html>
<body onload="initialize(30,70,5)">
<form method="GET" >
Enter latitude: <input type ="text" name="lat" id="lat" / ><br/>
Enter longitude: <input type ="text" name="lang" id="lang"/ ><br/>
Enter Zoom level: <input type ="text" name="zoom" id="zoom"/ ><br/>
<input type="button" value ="dynamic_ display" onclick=" initialize(
document.getElementById('lat').value,
document.getElementById('lang').value,
document.getElementById('zoom').value)"/>
<input type="button" onclick=" initialize(32,72,6)" value="Manual_display"/>
</form>
<center><div id="googleMap" style="width:1000px;height:500px;"></div></center>
谢谢你的帮助。