问题
I have a problem with Google avoid highways. When you choose youre route it writes down the directions on the side. When you click on directions they get zoomed in on the map. The problem is that they dont get zoomed in in the midlle of the map, they are zoomed in edges and corners of the map. How do i make it zoom to center?
回答1:
As the issue is the same like here, the solution is also the same:
Create a custom infoWindow and pass it as infoWindow-option to the directionsRenderer, then you'll be able to center the infoWindow when it opens.
Step#1: create the infoWindow:
var infoWindow=new google.maps.InfoWindow();
Step#2: observe the domready-event of the infoWindow:
google.maps.event
.addListener(infoWindow,'domready',
function(){map.setCenter(this.getPosition());});
Step#3: initialize the DirectionsRender with the infoWindow-option
(replace your current initialization with it)
directionsDisplay = new google.maps
.DirectionsRenderer({infoWindow : infoWindow});
Put the 3 steps to the begin of initialize(), and everything should work as expected.
来源:https://stackoverflow.com/questions/13952810/show-info-window-in-center-of-the-map-google-avoid-highways