jquery - 将更多信息传递到 Google Maps InfoWindow
问题描述
我正在尝试将更多信息传递到 Google Maps 地图 InfoWindow,但不知何故它不起作用。这一定只是一个简单的愚蠢的事情,但我已经花了几个小时,但找不到它。
我的数据存储为:
res[i].id
res[i].name
res[i].date
等等
然后我输出它:
var marker = new google.maps.Marker({ position: new
google.maps.LatLng(res[i].position.lat,res[i].position.long),
title:'',
orderid:res[i].id,
map:map,
icon: icon,
});
google.maps.event.addListener(marker, "click", (function(id) {
return function() {
var contentString = '<div><b>Order ID:</b> '+id+'
<br><b>Name:</b> '+res[i].name+'</div>'
<br><b>Date:</b> '+res[i].date+'</div>';
infowindow.setContent(contentString);
infowindow.open(map, this);
}
})(res[i].id));
使用id
时输出正常,id
但我不知道如何传递其他变量。由于某种原因,名称和日期总是显示Cannot read property 'XXX' of undefined
我究竟做错了什么?注意这张地图上可能有很多标记,它是一个for
循环。
解决方案
找到了解决方案:
google.maps.event.addListener(marker, 'click', (function(marker,i){
return function(){
infoWindow.setContent(infoWindowContent[i]);
infoWindow.open(map, marker);
}
})(marker,i));
function getInfoWindowDetails(location){
var contentString = '<div id="content" style="width:270px;height:100px">' +
'<h3 id="firstHeading" class="firstHeading">' + location.name + '</h3>'+
'<div id="bodyContent">'+
'<div style="float:left;width:100%">'+ location.status + '</div>'+
'</div>'+
'</div>';
return contentString;
}
希望这对某人有帮助!
推荐阅读
- c# - C# listview 子项未显示
- django - 需要登录会话 Selenium 的 Django 中的测试视图
- php - 如果两次上传相同的文件名,如何在laravel中显示错误消息
- python - 逻辑回归数据的完全分离
- php - 我在这个 foreach 循环中做错了什么?
- javascript - 将 props 传递给封装在 HOC 中的 React Redux 连接组件
- javascript - Vue.js - 在悬停时添加删除按钮并在按下按钮时删除它
- asp.net - 用户“SQLLogin”的 Asp.net LocalDB (SQL) 登录失败
- node.js - 使用 eventemitter 监听事件
- hive - Impala - 将 MON-YY 转换为 YYYYMM