继续。在Distance between two locations隐藏部分地图
<html>
<head>
<script src="http://maps.googleapis.com/maps/api/js"></script>
<script type="text/javascript">
var directionsDisplay;
var directionsService;
var map;
function initialize()
{
directionsDisplay= new google.maps.DirectionsRenderer();
directionsService = new google.maps.DirectionsService();
var mapProp =
{
zoom: 7,
mapTypeId : google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById('textDirection'));
}
function showMap()
{
document.getElementById("googleMap").style.display = 'inline';
document.getElementById("textDirection").style.display = 'inline';
var start = document.getElementById('origin').value;
var end = document.getElementById('destination').value;
var directionsRequest =
{
origin : start,
destination : end,
travelMode : google.maps.TravelMode.DRIVING
}
directionsService.route(directionsRequest, function(response, status)
{
if(status === google.maps.DirectionsStatus.OK)
{
directionsDisplay.setDirections(response);
}
else
{
window.alert('Cannot');
}
});
}
function resetMap()
{
document.getElementById("origin").value = '';
document.getElementById("destination").value = '';
document.getElementById("googleMap").style.display = 'none';
document.getElementById("textDirection").style.display = 'none';
}
</script>
<style>
#textDirection{
width: 300px;
height: 60%;
float: right;
overflow-y: auto;
margin-top: 1%;
margin-right: 29%;
}
#googleMap{
width : 50%;
height : 60%;
top: 5%;
position : absolute;
margin-left: 5px;
}
</style>
</head>
<body onload="initialize()">
<form action="showmap1.php" method="post">
From: <input type="text" name="origin" id="origin" size="30" />
To:<input type="text" name="destination" id="destination" size="30" />
<input type="button" value="Search" onclick="showMap()" />
<input type="button" value="Reset" onclick="resetMap()" /><br />
<div id="googleMap"></div>
<div id="textDirection"></div>
</form>
</body>
</html>
从上面的代码中,我有以下问题:
(1)的JavaScript
当我运行上面的代码,我得到像下面的图像输出:
灰色部分是显示的地图。我想在第一次运行页面时将其隐藏起来。我应该如何修改它?
(2)JavaScript
当我搜索到正确的结果后,现在我尝试搜索空白目标。它显示下面的图像:
但是,以前的地图和路线与警报一起显示。我的预期输出仅显示警报消息“Can not”,没有地图和路线。我应该如何修改它?
(3)CSS
当我放大我的网页到120%,我的输出类似下面的图片:
哦,我的上帝,我看不到路。如果我把我的网页放大和缩小,情况会更糟糕。为什么以及如何在css中修改它?
尼斯......我有一个季度的问题。我尝试你的小提琴,我仍然看到地图和路线与警报(“不能”)。 –
不错^^...但这次地图不能显示你最新的提琴的方向... –
你能再次检查吗?我仍然展示它。 –