由于问题与 这里 ,解决方案也是一样的:
创建一个自定义的infoWindow并将其作为infoWindow选项传递给directionsRenderer,然后当它打开时,可以将infoWindow居中。
第1步:创建infoWindow:
var infoWindow = new google.maps.InfoWindow ();第二步:观察infoWindow的domready事件:
google.maps.event .addListener(infoWindow,'domready', function(){map .setCenter(this.getPosition());});步骤#3:使用infoWindow选项初始化DirectionsRender (用你的当前初始化代替它)
directionsDisplay = new google.maps .DirectionsRenderer {infoWindow:infoWindow});将3个步骤放在 initialize(),并且所有内容都应按预期工作。
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?
解决方案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.
更多推荐
在地图中心显示信息窗口
发布评论