<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