我确信有一种简单的方法可以做到这一点,但我似乎无法在 Google map 在线文档中找到它。我有一张带有几个圆圈的 map ,其想法是单击圆圈将打开一个新的 HTML 页面。
对于每个圆......
纬度经度定义:
var NZNorth=new google.maps.LatLng( -38.929764,176.009002);
圆变量:
var Circle1 = new google.maps.Circle({
center:NZNorth,
radius:250000,
strokeColor:"#FA0014",
strokeOpacity:1,
strokeWeight:1,
fillColor:"#FA0014",
fillOpacity:0.2
});
调用圈子:
Circle1.setMap(map);
那么要添加圆圈的超链接onclick,我需要做什么?我不确定是否必须声明每个圆的链接,然后在每个圆变量中包含 onclick 函数?
一如既往地感谢您的帮助!
最佳答案
如果有人遇到同样的问题,请将 URL 添加到您的变量中
var Circle1 = new google.maps.Circle({
center:NZNorth,
radius:250000,
strokeColor:"#FA0014",
strokeOpacity:1,
strokeWeight:1,
fillColor:"#FA0014",
fillOpacity:0.2,
URL:'http://www.bbc.co.uk'
});
然后添加监听器!
google.maps.event.addListener(Circle1, 'click', function() {
window.location = Circle1.URL;
});
关于javascript - 将 HTML 链接添加到 Google map 圆形元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18697007/