gpt4 book ai didi

javascript - 将监听器添加到弹出信息窗口的标记 - Google Maps API

转载 作者:行者123 更新时间:2023-11-30 18:18:08 26 4
gpt4 key购买 nike

如何向我的标记添加一个监听器,当单击该标记时它会显示“Hi”。我的代码看起来像:

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?key=AIzaSyAGcwOypxqebsKcF-A6pZUqDvijKbjltw0&sensor=false">
</script>
<script type="text/javascript">
function initialize() {
var myLatlng = new google.maps.LatLng(61.455019, 23.84559);

var myOptions = {
zoom: 15,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.TERRAIN
}

var myMap = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

var myMarker = new google.maps.Marker({
position: myLatlng,
map: myMap,
});

google.maps.event.addListener(myMarker, 'click',
function()
{
var htmlString = "Hi";
myMarker.openInfoWindowHtml(htmlString);
}
);
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>

我想我在调用 addListener 事件时出错了。

最佳答案

参见 documentation on infowindow对于 Google Maps API v3,没有 .openInfoWindowHtml 方法。

Working example from the documentation

Working version of your map using v3 syntax

关于javascript - 将监听器添加到弹出信息窗口的标记 - Google Maps API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12769763/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com