1

如何抵消 panTo 函数?单击标记时,我想平移到它,但不将标记放在屏幕中央。

我想将它(x 和 y)偏移屏幕宽度和高度的所需百分比。

google.maps.event.addListener(marker, 'click', function() {
   map.panTo(loc);
});

谢谢

4

1 回答 1

4

An easier approach than the calculation suggested in the comments could be to:

  1. use panTo to center the map at the given position
  2. use panBy to apply the desired offset

The dimensions of a element may be retrieved via offsetWidth/offsetHeight

Sample:

google.maps.event.addListener(marker, 'click', function() {
  var map = this.getMap(),
      div = map.getDiv();
  map.panTo(this.getPosition());
  map.panBy(div.offsetWidth/4, div.offsetHeight/4);
});
于 2013-08-17T22:48:07.287 回答