我有js功能
function getDriving() {
markers.length = 0;
var todayval = new Date();
var newtodaydata = new Date(todayval.toDateString());
console.log(newtodaydata);
var url = $('#map').data('request-url2');
$.getJSON(url,
function (data) {
$.each(data,
function (i, item) {
markers.push({
'location': new google.maps.LatLng(item.Latitude, item.Longitude),
'map': map,
'weight': item.Speed,
'radius': 10,
'date': item.CurrentDateTime,
'imei': item.Imei
});
});
var todaymarkersfiltered = markers.filter(function (marker) {
var getDate = marker.date.match(/\d/g).join('');
var markerDate = new Date(parseFloat(getDate));
console.log(markerDate);
return (markerDate === todayval);
});
var pointArray = new google.maps.MVCArray(todaymarkersfiltered);
console.log(pointArray);
heatmap = new google.maps.visualization.HeatmapLayer({
data: pointArray
});
heatmap.setMap(map);
});
};
以下是var newtodaydata = new Date(todayval.toDateString());
周一2018年1月25日00:00:00 GMT + 0200(FLE标准时间)
在console.log(markerDate);
中我有2个标记具有相同的数据
但在todaymarkersfiltered
我没有标记。
我的问题在哪里?
感谢您的帮助。
答案 0 :(得分:0)
我发现了问题,我将条件===
重写为==
并将其设为markerDate.toDateString() == todayval.toDateString()
我重写了这样的代码
function getDriving() {
markers.length = 0;
var todayval = new Date();
var url = $('#map').data('request-url2');
$.getJSON(url,
function (data) {
$.each(data,
function (i, item) {
markers.push({
'location': new google.maps.LatLng(item.Latitude, item.Longitude),
'map': map,
'weight': item.Speed,
'radius': 10,
'date': item.CurrentDateTime,
'imei': item.Imei
});
});
var todaymarkersfiltered = markers.filter(function (marker) {
var getDate = marker.date.match(/\d/g).join('');
var markerDate = new Date(parseFloat(getDate));
return (markerDate.toDateString() == todayval.toDateString());
});
var pointArray = new google.maps.MVCArray(todaymarkersfiltered);
console.log(pointArray);
heatmap = new google.maps.visualization.HeatmapLayer({
data: pointArray
});
heatmap.setMap(map);
});
};
现在一切都好吗