我正在尝试在格式化的表格中打印位置地址和last_seen时间。从res.location[i].lat, res.location[i].long
正确获取格式化地址。但是当我将last_seen
附加到字符串时,只获取最后一个记录的值。我的意思是为last_seen
获取相同的值,这是最后一条记录的值。
请帮我找出错误的地方?
function getAddress(res)
{
var html = '';
var latitude = '';
var longitude = '';
var location_id = '';
for (i = 0; i < res.location.length; i++){
latitude = res.location[i].lat;
longitude = res.location[i].long;
location_id = res.location[i].id;
var last_seen = moment(res.location[i].created_at).calendar();
console.log(location_id);
console.log(last_seen);
url = 'https://maps.googleapis.com/maps/api/geocode/json?latlng='+parseFloat(latitude)+','+ parseFloat(longitude)+'&key=AIzaSyCJeRq6PHsq6DOwC3YDeIR1357I3w5BPLI';
$.ajaxq ('getAddress', {
url: url,
type: 'post',
data:
{
delay: 5
},
success: function (response)
{
console.log(last_seen);
html = '<tr><td>' + response.results[0].formatted_address+'<br />Last Seen : '+ last_seen +'</td><td><input type="checkbox" checked="true" name="selected-location" id="'+location_id +'" value="'+location_id +'"></td></tr>';
$('#single-user tr:last').after(html);
}
});
}
}