嗨,我有一张显示穿梭方向的地图,下面是地图和方向初始化代码
var centerLatlng = new google.maps.LatLng(-34.942799,138.553365);
var myOptions = {
zoom: 13,
center: centerLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoomControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.LARGE
},
panControl:true,
streetViewControl: false,
OverviewMapControlOptions:
{
opened: true
}
};
var map = new google.maps.Map(document.getElementById("map-guide-google-map"), myOptions);
以下是显示方向
function DisplayDirection(directionList){
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer({
markerOptions: {
visible:false
}
});
directionsDisplay.setMap(map);
//Request 0
var increaseSize = 7;
var index =0;
var theoryCurrentEndIndex = index + increaseSize;
var maxmimumIndex = directionList.length-1;
var origin = directionList[index];
var destination = theoryCurrentEndIndex < maxmimumIndex?directionList[theoryCurrentEndIndex]:directionList[maxmimumIndex];
var actualCurrentEndIndex = theoryCurrentEndIndex < maxmimumIndex?theoryCurrentEndIndex: maxmimumIndex;
var waypoints = new Array();
if(actualCurrentEndIndex-index>1) {
for(var i=index+1;i<actualCurrentEndIndex;i++) {
waypoints.push(
{
location:directionList[i],
stopover:true}
);
}
}
var request = {
origin: origin,
destination: destination,
waypoints : waypoints,
provideRouteAlternatives:false,
travelMode: google.maps.TravelMode.WALKING,
unitSystem: google.maps.UnitSystem.METRIC
}
directionsService.route(request, function(result, status) {
if(status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(result);
}
}) ;
}
如何重置 LatLongBounds 以显示所有停止点并使地图居中