下面的代码在 html 页面中工作,但是当我在 aspx 页面中使用相同的代码时,地图没有出现。谁能告诉我我做错了什么。
我有 5 个中途停留点作为航点。我想在地图上将它们全部显示为推送点和旅行路线。
<html>
<head>
<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(17.42354, 78.46290);
var mapOptions = {
zoom: 6,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: chicago
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
directionsDisplay.setMap(map);
}
function calcRoute() {
var start = "17.44438,78.44251";
var end = "17.3687826,78.5246706";
var waypts = [];
waypts.push({
location: "17.44438,78.44251",
stopover: true
});
waypts.push({
location: "17.413384,78.461142",
stopover: true
});
waypts.push({
location: "17.38364,78.466964",
stopover: true
});
waypts.push({
location: "17.3836013,78.4869135",
stopover: true
});
waypts.push({
location: "17.3687826,78.5246706",
stopover: true
});
var request = {
origin: start,
destination: end,
waypoints: waypts,
optimizeWaypoints: true,
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);
window.onload = function () { initialize(); calcRoute(); };
</script></head>
<body>
<form id="form1" runat="server">
<div id="map-canvas"></div>
</form>
</body>
</html>