![](/img/trans.png)
[英]How can I make Infowindow when I click a marker on the googlemap
[英]Execute Function on click of googlemap marker
我想点击googlemap标记来调用一个函数。 我在这里阅读了一些答复,但没有一个对我有用。 单击标记时没有任何反应。 以下是我的googlemap代码。 函数testCase()没有被调用。 注意,此代码包含一些应忽略的JSP代码。
var locations = [];
<%
for(Object t: posts)
{
ReportModel md = (ReportModel) t;
String toSplit[] = md.getCaseLocation().split(",");
%>
locations [locations.length] = ['<%=md.getCategory()%>', <%=toSplit[0]%>, <%=toSplit[1]%>,<%=md.getCode()%>, 4];
<%
}
%>
console.log(locations);
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 14,
zoomControl: false,
center: new google.maps.LatLng(6.4549, 3.4246),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
testCase(locations[i][3]);
}
})(marker, i));
function testCase(id)
{
alert(id);
}
您可以尝试将侦听器添加到标记:
marker.addListener('click', function() {
console.log('TEST CLICKED TO ENSURE THAT IT WORKS')
testCase(locations[i][3])
})
参考文献:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.