我正在使用Google Maps Directions API生成包含往返地点的路线的地图,但如何使用javascript API获取实际的文字说明?
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var mapOfDirections;
directionsDisplay = new google.maps.DirectionsRenderer();
var center = new google.maps.LatLng(lat, lon);
var mapOptions = {
zoom:6,
center: center
}
maps = new google.maps.Map(document.getElementById('main'), mapOptions);
directionsDisplay.setMap(maps);
var request = {
origin:from,
destination:to,
travelMode:google.maps.TravelMode.DRIVING
};
directionsService.route(request, function(result, status){
if(status==google.maps.DirectionsStatus.OK) directionsDisplay.setDirections(result);
});
答案 0 :(得分:0)
这是我最终如何做到的:
function calculateDirections(){
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var directionsOptions = {
panel:document.getElementById('directionsDiv')
}
directionsDisplay = new google.maps.DirectionsRenderer(directionsOptions);
var request = {
origin:from,
destination:to,
travelMode:google.maps.TravelMode.DRIVING
};
directionsService.route(request, function(result, status){
if(status==google.maps.DirectionsStatus.OK) directionsDisplay.setDirections(result);
});
}