<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script type="text/javascript">
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var chicago = new google.maps.LatLng(41.850033, -87.6500523);
var mapOptions = {
zoom: 7,
center: chicago
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
directionsDisplay.setMap(map);
}
function calcRoute() {
var start = document.getElementById('start').value;
var end = document.getElementById('end').value;
var request = {
origin: start,
destination: end,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function (response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
HTML代码:
<div id="menu2" class="tab-pane fade">
<div class="col-md-12">
<p>Hello...</p>
</div>
</div>
<div id="menu2" class="tab-pane fade">
<div class="col-md-12">
<input type="text" placeholder="Source" name="start" id="start" value="noida">
<input type="text" placeholder="Source" name="end" id="end" value="delhi">
<input id="Button1" type="button" value="button" onclick="calcRoute()" />
<div id="map-canvas"></div>
</div>
</div>
在该代码中,我想要显示其具有一个id = “MENU2” 地图没有显示的标签内谷歌地图。当我点击id(menu1)时会显示hello,但当我点击id(menu2)文本字段正在呈现,但点击按钮时它不显示地图。我该如何解决这个问题?
谢谢
你得到任何控制台错误? –
不,我没有得到任何错误,但当我点击按钮时,只有线显示没有加载地图。 – kevin