我无法在 Google API 上为公交路线创建自定义折线。仅渲染部分路线,而不是全部。它适用于驾驶、步行和骑自行车,但不适用于过境。不知道我到底错过了什么。如果有人遇到同样的问题,请帮忙!我在小提琴中做了一个例子:
http://jsfiddle.net/srs/vF2e9/1/
示例代码
var directionsDisplay, map;
var directionsService = new google.maps.DirectionsService();
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var mapOptions = {
zoom: 7,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: new google.maps.LatLng(41.850033, -87.6500523)
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
directionsDisplay.setMap(map);
calcRoute();
}
function calcRoute() {
var start = "98012";
var end = "98014";
var request = {
origin: start,
destination: end,
travelMode: google.maps.TravelMode.TRANSIT
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
var polyLine = new google.maps.Polyline({
strokeColor: '#FF0000'
});
var options = {};
options.directions = response;
options.map = map;
options.polylineOptions = polyLine;
//options.suppressMarkers = true;
directionsDisplay.setOptions(options);// = new google.maps.DirectionsRenderer(options);
polyLine.setMap(map);
//directionsDisplay.setDirections(response);
}
});
}