问题:是否有可能用Google创建文本,即使在缩放/移出或平移时也能在窗口上盘旋在固定位置?
到目前为止我已经尝试过的内容:--我已经知道,使用以下代码可以使用infowindow:
var contentString = "<div>Hello!</div>";
var infowindow = new google.maps.InfoWindow({
content: contentString
});
marker.addListener('click', function() {
infowindow.open(map, marker);
});
但是前面的信息窗口需要一个标记,据我所知,标记只能在地图上有固定的位置(我无法找到如何在屏幕中央放置一个标记,即使用户移动地图时也不能保持它)。
有谁知道把文字放在地图中间的方法吗?它可能与信息窗口或其他方法。
发布于 2016-07-25 06:57:33
如果要使用InfoWindow,只需为标记设置visible: false
,然后在地图中心位置发生变化时更改标记的位置:
/* Invisible marker for the InfoWindow */
textmarker = new google.maps.Marker({
position: map.getCenter(),
map: map,
visible: false
});
/* Center change handler to always center the marker */
map.addListener('center_changed', function() {
textmarker.setPosition(map.getCenter());
});
/* adding the info window */
var infowindow = new google.maps.InfoWindow({
content: "Your Text can be placed here"
});
infowindow.open(map, textmarker);
发布于 2016-07-24 19:44:10
假设文本位于地图上方的静态位置上,您可以使用CSS完成此操作:
<div class="map-container">
<-- google map div here -->
<div class="textbox">Static Text</div>
</div>
CSS:
.map-container {
position: relative;
}
.textbox {
position: absolute;
left: 50%:
top: 50%;
transform: translateX(-50%);
transform: translateY(-50%);
z-index: 1000;
}
https://stackoverflow.com/questions/38555845
复制相似问题