我的简单javascript代码如下。在此我在填充位置数组时收到错误“无法设置未定义的属性”。
var locations = [];
for (var i=0;i<center_add.length;i++)
{
var geocoder = new google.maps.Geocoder();
// center_add[i].toString();
// alert(center_add[i].toString());
geocoder.geocode( { 'address': center_add[i].toString()}, function(results, status) {
locations[i]=[];
if (status == google.maps.GeocoderStatus.OK) {
locations[i][0] = center_add[i].toString();
// Uncought TypeError="Can not set property '0' of undefined.
locations[i][1]= results[0].geometry.location.lat();
locations[i][2]= results[0].geometry.location.lng();
}
});
}
提前致谢....