我正在尝试使用gmap3 插件向谷歌地图动态添加标记。在下面的代码中,当我将变量 _addressList传递给 .gmap() 时,它只显示 1 个标记。确切地说,只有最后一个标记显示{address: "100e 800n, 84321", data: "marker 4"}
// address sample format
{address: "727e 800n, 84321", data: "marker 1"},
{address: "900e 800n, 84321", data: "marker 2"},
{address: "200e 800n, 84321", data: "marker 3"},
{address: "100e 800n, 84321", data: "marker 4"},
这是我的 ajax 获取代码。任何想法是我做错了什么?
$.ajax({type: "GET",
url: url,
data: poststr,
success: function(data)
{
var _add = new Array();
var _data;
for (i = 0; i < data.length; i++)
{
_data = '{address: "'+data[i][1]+'", data: "'+data[i][0]+'"}';
_add.push(_data);
}
//convert string to JSON
var _addressList = eval("(" + _add + ")");
$("#map-canvas").gmap3({
marker:{
values: [
_addressList
]
}
});
},
dataType: "JSON"
});
}