帮助我用谷歌方向包括距离矩阵
在我的网站上,我使用以下代码获取 Google 地图。我应该添加什么代码来显示往返之间的距离以及旅行时间?
谢谢你。
<div style="width: 298px;">
<div id="map" style="width: 298px; height: 400px; float: left;"></div>
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer();
var map = new google.maps.Map(document.getElementById('map'), {
zoom:7,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById('panel'));
var request = {
origin: '<?php echo $contents['pickupname']; ?>',
destination: '<?php echo $contents['dropoffname']; ?>',
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});