[英]move google map to the left on marker click
When I click on a marker I don't want to center the map on the marker but move it to a bit to the left so I can display a window with some information on the right. 当我单击标记时,我不想将地图居中放置在标记上,而是将其向左移动一点,以便在右侧显示一些信息的窗口。 I think it would be easier to use setCenter() but then I need a position next to the marker.
我认为使用setCenter()会更容易,但随后我需要在标记旁边放置一个位置。
I guess i would have to do some calculations based on the markers latitude and longitude but I do not know how to proceed with this. 我想我将不得不根据标记的纬度和经度进行一些计算,但是我不知道该如何进行。 Does anyone know how to calculate to a position based on a markers latitude and longitude?
有人知道如何根据标记的纬度和经度来计算位置吗? or is there another (easier) way?
还是有另一种(更简便的)方式?
Add an event listener to the marker. 将事件侦听器添加到标记。
Once marker is clicked, get marker position using getPosition()
. 单击标记后,使用
getPosition()
获取标记位置。 To move the map to the left you want to center the map to a point to the right of the marker. 要将地图移到左侧,您需要将地图居中到标记右侧的一点。 So make a new set of coordinates with same lat and lng + 1 degree maybe.
因此,可能要创建一组新的坐标,它们的纬度和经度应为+ 1度。
Then you can use setCenter()
or panTo()
methods to move to the map in your desired direction. 然后,您可以使用
setCenter()
或panTo()
方法沿所需方向移动到地图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.