multiple locations on map

Go To


im trying to create an event at load time for my application to display data from a CSV excel file.

Basically, Im trying to reference data, from an Excel CSV file, that will in turn populate my google map with locations from the file (CSV).

This makes it easier for me to add data to the CSV and always be able to populate my map with the latest data.

Im using javascript and jQuery. Thanks for any help.

2012-04-03 23:58
by JColling


You're going to need a script to parse the CSV file into an array or loop statement. I'd recommend using PHP's fgetcsv method:

$row = 1;
$output_array = array();
if (($handle = fopen("file_name.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);
        echo "<p> $num fields in line $row: <br /></p>\n";
        for ($c=0; $c < $num; $c++) {
            $output_array[] = $data[$c];

This basically opens the file, reads it, stores all the rows in an array for front-end presentation. In your view, you can do something like:

echo '<script type="text/javascript">';
foreach($output_array as $data_chunk)
   echo 'JavaScript line for Geolocation';
echo '</script>';
2012-04-04 00:44
by hohner
In that code, is my CSV being called from a server location, or from local computer? Thanks - JColling 2012-04-04 01:10
From a server location. You can't get PHP to reach into your computer's hard drive and pluck out the right file. Unfortunately - hohner 2012-04-04 01:12
lol good point. Im gonna try out your suggestion today. Thanks - JColling 2012-04-04 14:27
Strangely, Im not getting an error but at the same time it is not working....Is this meant work for mobile platforms? Im using Eclipse editor. Thank you - JColling 2012-04-04 15:06
Is their a solution to this, only in Javascript or jQuery? I cant use PHP. But I do thank you for your answer. : - JColling 2012-04-06 00:30
The simple answer is No. JavaScript cannot read files like this - you need a server-side script (like PHP) which can open the file and parse its content - hohner 2012-04-06 01:16
can you give me a real life example? Im confused now... Thanks for posting by the way. ;- - JColling 2012-04-17 04:01