在地图中心显示信息窗口

编程入门 行业动态 更新时间:2024-10-22 18:45:09
本文介绍了在地图中心显示信息窗口 - Google避开高速公路的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 Google在避开高速公路时遇到问题。当你选择你的路线时,它会写下方向。当你点击他们在地图上放大的方向时。问题在于,他们不会在地图的midlle中放大,而是放大地图的边缘和角落。

解决方案

由于问题与 这里 ,解决方案也是一样的:

创建一个自定义的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.

更多推荐

在地图中心显示信息窗口

本文发布于:2023-10-29 08:09:11,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:窗口   地图   中心   信息

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!