我想将信息窗口移到标记之外。在此示例中,信息窗口在标记的同一点打开。
var anchor = new google.maps.MVCObject();
anchor.set("position",event.latLng);
infoWindow.open(map,anchor);
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>
更改 Google 信息窗口中的样式
带有 HTML 信息窗口和图像标记图标的中心窗口:
.gm-style-iw-t {
right: 0px !important;
}