我有一个代码,每次从保存的txt文件中获取gps数据时生成一个标记,然后每隔5分钟创建一个标记我想为每个标记创建一个信息窗口,其中infoWindow的内容是时间该标记已创建。我想在哪里增加infoWindow?
<script type="text/javascript">
var myCenter=new google.maps.LatLng(10.294097000000000000,123.897455799999990000);
var marker;
var map;
var mapProp;
function initialize()
{
mapProp = {
center:myCenter,
zoom:17,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
setInterval('mark()');
}
function mark()
{
$date = date('Y-m-d H:i:s');
map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
var file = "gps.txt";
$.get(file, function(txt) {
var lines = txt.split("\n");
for (var i=0;i<lines.length;i++){
console.log(lines[i]);
var words=lines[i].split(",");
if ((words[0]!="")&&(words[1]!=""))
{
marker=new google.maps.Marker({
clickable: true,
position:new google.maps.LatLng(words[0],words[1]),
});
marker.setMap(map);
map.setCenter(new google.maps.LatLng(words[0],words[1]));
//document.getElementById('speed').innerHTML=words[3];
//document.getElementById('course').innerHTML=words[4];
var info = new google.maps.InfoWindow({
content: '<b>Speed:</b> ' + Date + ' knots'
});
google.maps.event.addListener(marker, 'click', function() {
info.open(map, marker);
}
}
marker.setAnimation(google.maps.Animation.BOUNCE);
});
google.maps.event.addListener(marker, 'click', function() {
marker.info.open(map, marker);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
答案 0 :(得分:0)
您应该只能更改内容值:
var info = new google.maps.InfoWindow({
content: new Date().toString()
});
这将为您提供类似"Tue Jan 21 2014 10:48:10 GMT+0000 (GMT Standard Time)"
setInterval('mark()');
只需使用:
mark();