如何重新定位谷歌地图信息窗口

时间:2016-03-22 23:56:34

标签: javascript google-maps google-maps-api-3

如何在Google地图中重新定位信息窗口?

我希望窗口在标记处打开,小凹痕朝向标记。

这是我的代码我认为像素偏移是改变但不确定的选项。当我将y调整为70时,它会显示在标记下方但是如何更改缩进以进行翻转?

$infowindow = new google.maps.InfoWindow({
  content: "Drag the map to re-center location",
  pixelOffset: new google.maps.Size(0, 70), // want the window to open underneathe with the indent facing up
});

1 个答案:

答案 0 :(得分:1)

原生google.maps.InfoWindow(目前)不支持您正在寻找的行为。您可以创建feature request in the issue tracker for the Google Maps JavaScript API v3

对于现在可以使用的内容,InfoBox可能会执行您要查找的内容,请参阅example in the documentation

代码段

html,
body,
#map_canvas {
  height: 100%;
  width: 100%;
}
<script src="http://maps.googleapis.com/maps/api/js"></script>
<script src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox.js"></script>
<div id="map_canvas" style="width: 100%; height: 400px"></div>
<p>
  This example shows the "traditional" use of an InfoBox as a replacement for an InfoWindow.
heartbeat_replys = ('0xFF', '0x0F', '0xF0', '0x00',
                '0xB0', '0x40', '0xBF', '0x4F',
                '0xE9', '0x19', '0xE6', '0x16')


heartbeat_replys = list(zip(*[iter(heartbeat_replys)] * 4))


beats = dict(zip(heartbeat_replys , range(len(heartbeat_replys))))

arg = ('0xFF', '0x0F', '0xF0', '0x00')

print(heartbeat_replys[(beats[arg] + 1) % len(heartbeat_replys)])

('0xB0', '0x40', '0xBF', '0x4F')