Skip to content

How to read from CSV for Google Maps

agershun edited this page Dec 28, 2014 · 4 revisions

How to read from CSV for Google Maps?

Source: StackOverflow.com

Question

The CSV file is as follows : data.csv

'Chicago', 41.878113, -87.629798, 4
'New York', 40.714352, -74.005973, 5 
'Los Angeles', 34.052234, -118.243684, 3
'Phoenix', 33.4483771, -112.0740373, 2 
'Dallas', 32.7802618, -96.8009781, 5

I am reading the csv (data.csv) and copying it into an array data, and copying data to citymap.

Answer

I recommend use more complicated CVS parser for CVS parsing. Alasql library can loading and parsing CSV files (XLSX as well):

alasql('SELECT MATRIX * FROM CVS("data.csv", {headers:false})',[],function(data){
    // process data array
});

This is working at jsFiddle.

Clone this wiki locally