基本上,我需要获得支持才能显示到达目的地的步行和公交指示。
答案 0 :(得分:0)
这里有2个请求会为随机城市生成路线,请确保复制您的api密钥。
步行路线
行车路线
如果您想使用JS API进行操作(我编写了一个小示例),请粘贴您的api密钥,您可以更改出行方式,步行和驾车。
<!DOCTYPE html>
<html>
<head>
<title>Simple Map</title>
<meta name="viewport" content="initial-scale=1.0">
<meta charset="utf-8">
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var map;
var directions;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 8
});
directions = new google.maps.DirectionsService
directions.route({
origin: 'Tokyo',
destination: 'Yokohama',
region: "Ja",
travelMode: 'TRANSIT',
unitSystem: google.maps.UnitSystem.IMPERIAL
}, (route)=> console.log(route))
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBsYuTQdeFRaWzydcZnD6Dk39qCqDHtuDU&callback=initMap"
async defer></script>