简体   繁体   English

如何将CSV文件导入到Webapp的javascript中,以便我可以在Google Maps画布上放置地址标记?

[英]How do import a CSV file into the javascript for a webapp so that i can place address markers on a google maps canvas?

So I am a bit new to javascript and the Google maps API's. 因此,我对javascript和Google Maps API有点陌生。 Currently I can place a marker given a single hard coded address variable called codeAddress. 目前,我可以给一个标记一个给定的硬编码地址变量codeAddress来放置标记。

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);
        }
    });
}

The problem is that I need to be able to place multiple markers based on location and need to be able to parse address data from a CSV file or from an sql database. 问题是我需要能够根据位置放置多个标记,并且需要能够从CSV文件或sql数据库解析地址数据。

thanks for the help. 谢谢您的帮助。

I've used the jquery-csv plugin to process csv files. 我使用了jquery-csv插件来处理csv文件。

If you can give more specifics on where this csv file is coming from, and how it will be loaded, I can give info on how you can convert this into a javascript array. 如果您可以提供有关此csv文件的来源以及如何加载的更多详细信息,请提供有关如何将其转换为javascript数组的信息。 Will this file be on the server already? 该文件已经在服务器上了吗? If so, then it would make more sense to do some server side processing to read the file. 如果是这样,那么进行一些服务器端处理来读取文件将更有意义。

The following shows how to modify your code to work with an array of multiple addresses: 下面显示了如何修改代码以使用多个地址的数组:

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);
        }
    });
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何将 fonts 从谷歌 fonts 导入 javascript,这样我就可以将它用于我的 ZFCC790C72A86190DE - How would I import fonts from google fonts into javascript, so i can use it for my canvas? Google如何在画布上滚动Google地图样式? - How can I do google maps style scrolling on canvas? 如何使用地方网址创建谷歌地图标记 - How to create google maps markers with place url 如何使标记可拖动,标记和删除? 使用Google Maps JavaScript API - How do I make markers draggable, labeled, and deletable? with Google maps javascript API 如何将位智事件标记添加到带有流量的Google Maps javascript API生成的地图中? - How do I add waze incident markers to a google maps javascript API-generated map with traffic? 我应该如何配置 Javascript Webapp 以便它可以使用 Web 浏览器查看 Google 云存储中的文件 - How should I configure a Javascript Webapp so that it can use a Web Browser to view files in Google Cloud storage 从C#渲染的Google Maps JavaScript不会放置标记 - Rendered JavaScript from C# for Google Maps does not place markers 如何将标记添加到带有延迟的Google地图 - How do I add the markers to the google maps wth delays Javascript/谷歌地图 - 无法删除标记 - Javascript/Google Maps - Can't remove markers 如何使用 Google Maps API 自定义不同的标记 CSS? - How do I customize different markers CSS with Google Maps API?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM