【发布时间】:2016-01-10 21:58:26
【问题描述】:
续。在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
在我搜索到正确的结果后,现在我尝试搜索一个空白的目的地。它显示了下图:
但是,之前的地图和路线会与警报一起显示。我的预期输出仅显示没有地图和路线的警报消息“不能”。我应该如何修改它?
(3) CSS
当我将网页放大到 120% 时,我的输出如下图所示:
天哪,我看不到路线。如果我把我的网页放大得越来越大,那就更糟糕了。为什么以及如何在 css 中修改它?
【问题讨论】:
标签: javascript html css google-maps-api-3