我是新來使用谷歌地圖API谷歌地圖API的例子,我使用的谷歌關閉文檔一些示例代碼不工作,我想知道如果有人能幫助我解決它爲什麼止跌」爲我工作?下面是代碼本身:<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=true" ></script>
沒有工作
<script>
var directionDisplay;
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,
mapTypeId: google.maps.MapTypeId.ROADMAP,
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.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
</script>
這裏是HTML:
` <body onload="initialize()">
<div>
<b>Start: </b>
<select id="start" onchange="calcRoute();">
<option value="chicago, il">Chicago</option>
<option value="st louis, mo">St Louis</option>
<option value="joplin, mo">Joplin, MO</option>
<option value="oklahoma city, ok">Oklahoma City</option>
<option value="amarillo, tx">Amarillo</option>
<option value="gallup, nm">Gallup, NM</option>
<option value="flagstaff, az">Flagstaff, AZ</option>
<option value="winona, az">Winona</option>
<option value="kingman, az">Kingman</option>
<option value="barstow, ca">Barstow</option>
<option value="san bernardino, ca">San Bernardino</option>
<option value="los angeles, ca">Los Angeles</option>
</select>
<b>End: </b>
<select id="end" onchange="calcRoute();">
<option value="chicago, il">Chicago</option>
<option value="st louis, mo">St Louis</option>
<option value="joplin, mo">Joplin, MO</option>
<option value="oklahoma city, ok">Oklahoma City</option>
<option value="amarillo, tx">Amarillo</option>
<option value="gallup, nm">Gallup, NM</option>
<option value="flagstaff, az">Flagstaff, AZ</option>
<option value="winona, az">Winona</option>
<option value="kingman, az">Kingman</option>
<option value="barstow, ca">Barstow</option>
<option value="san bernardino, ca">San Bernardino</option>
<option value="los angeles, ca">Los Angeles</option>
</select>
</div>`
據我瞭解u需要谷歌ID /關鍵可以做谷歌地圖。你是否有一個? – 2013-03-15 16:23:20
我在腳本的最頂端? – davidbenjamin998 2013-03-15 16:25:08
當我添加我的API密鑰時,我總是收到以下消息: Google已經禁止將Google Maps API用於此應用程序。所提供的密鑰不是有效的Google API密鑰,也未授權此網站上的Google Maps JavaScript API v3。如果您是此應用程序的所有者,您可以在這裏瞭解如何獲取有效密鑰:https://developers.google.com/maps/documentation/javascript/tutorial#api_key – davidbenjamin998 2013-03-15 16:25:59