Show info window in center of the map - Google avoid highways

谁都会走 提交于 2020-01-15 02:39:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!