如何在此代码中定义锚点谷歌地图API的偏移量

问题描述 投票:0回答:2

我想将信息窗口移到标记之外。在此示例中,信息窗口在标记的同一点打开。

var anchor = new google.maps.MVCObject();
                anchor.set("position",event.latLng);
                infoWindow.open(map,anchor);
google-maps-api-3 anchor infowindow
2个回答
0
投票

A google.maps.Marker 是 InfoWindow 的有效锚点。

var infoWindow = new google.maps.InfoWindow();
infoWindow.setContent("some content");
infoWindow.open(map,marker);

概念证明小提琴

代码片段:

function initialize() {
  var map = new google.maps.Map(
    document.getElementById("map_canvas"), {
      center: new google.maps.LatLng(37.4419, -122.1419),
      zoom: 13,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });
  var marker = new google.maps.Marker({
    position: map.getCenter(),
    map: map
  });
  var infoWindow = new google.maps.InfoWindow();
  infoWindow.setContent("some content");
  infoWindow.open(map, marker);
}
google.maps.event.addDomListener(window, "load", initialize);
html,
body,
#map_canvas {
  height: 100%;
  width: 100%;
  margin: 0px;
  padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map_canvas"></div>


0
投票

更改 Google 信息窗口中的样式

带有 HTML 信息窗口和图像标记图标的中心窗口:

.gm-style-iw-t {
        right: 0px !important;
}
© www.soinside.com 2019 - 2024. All rights reserved.