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.
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";
$row++;
for ($c=0; $c < $num; $c++) {
$output_array[] = $data[$c];
}
}
fclose($handle);
}
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>';