如何将CSV文件导入Web应用程序的javascript中,以便在google地图画布上放置地址标记?
所以我对javascript和GoogleMapsAPI有点陌生。目前,我可以在给定一个硬编码地址变量codeAddress的情况下放置一个标记如何将CSV文件导入Web应用程序的javascript中,以便在google地图画布上放置地址标记?,javascript,html,csv,maps,Javascript,Html,Csv,Maps,所以我对javascript和GoogleMapsAPI有点陌生。目前,我可以在给定一个硬编码地址变量codeAddress的情况下放置一个标记 codeAddress("99362"); function codeAddress(address) { geocoder.geocode({ 'address': address }, function (results, status) { if (status == google.maps.Ge
codeAddress("99362");
function codeAddress(address) {
geocoder.geocode({
'address': address
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
问题是,我需要能够基于位置放置多个标记,并且需要能够解析CSV文件或sql数据库中的地址数据
谢谢您的帮助。我已经使用了来处理csv文件
如果您可以提供更多关于这个csv文件来自何处以及如何加载的详细信息,我可以提供有关如何将其转换为javascript数组的信息。此文件是否已在服务器上?如果是这样,那么做一些服务器端处理来读取文件会更有意义
下面显示了如何修改代码以使用多个地址的数组:
var addresses = ["99362", "01010", "12345"];
jQuery.each(addresses, function(index, address) {
geocoder.geocode({
'address': address
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
// we only need to center the map the first time
if (index == 0)
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
})
在发布答案时,您应该提供更多信息,而不仅仅是一个链接。你链接到的页面可能会移动或被取下,而这个答案在将来将变得毫无用处。可以在链接和代码示例中找到的内容的描述非常棒!