[Drupal] How to create map markers on the map automatically from CSV file.
A comma-separated values (CSV) file stores tabular data (numbers and text) in plain-text form. A CSV file have of number of records, separated by line breaks; fields in each record separated by some other character or string, usually a comma or tab. All records have an identical sequence of fields.
The fgetcsv() function parses a line from an open file, checking for CSV fields. The fgetcsv() function stops returning on encountering a new line, a specified length, or the EOF, whichever comes first.
Syntax :
fgetcsv(file,length,separator,enclosure)
file - Specifies the file to check (Required)
length - Specifies the maximum length of a line (Optional)
separator - Character that specifies the field separator. Default is comma ( , ) (Optional)
enclosure - Character that specifies the field enclosure character. Default is " (Optional)
The CSV file is :
a, b, c, d, e, f
Output of the code is :
Array ( [0] => a [1] => b [2] => c [3] => d )
In this case latitude and longitude are in CSV files. Fetch these values from the CSV file and then mark on the map.
- A map with controls and one marker displayed, automatically centering view port.
$("#map1").gMap({ markers: [{ latitude: 47.660937, longitude: 9.569803 }] });
- Changing the map type to physical view.
$("#map2").gMap({ maptype: G_PHYSICAL_MAP });
- An info window that pops up in the map.
$("#map3").gMap({ markers: [{ latitude: 47.660937, longitude: 9.569803, html: "Tettnang, Germany", popup: true }], zoom: 6 });