Google Maps Will Not Accept My .csv File

Google Maps expects a .csv file containing data to place on a map. My test file has 5 rows and 5 columns. The first row is a header with column names. My file ends with the usual null characters. It failed to load. I added a \r\n to the end, it still failed. I added \n to the end of the last line, it still failed to load. I surrounded all the data with double quotes and it still failed. However, if I remove the extra stuff , load it into Excell, and then save it as a .csv file, it works.
What am I missing here? Why does the Excell .csv file work?

Hello @fredstout ,

Notepad++ is a good tool for examining files.
I often use it to examine text files that may have some characters that are hidden and unwanted.

I suggest you compare (add a compare plugin) your two files to see what the issue was with the original file.

I only had CR LF in above and added the extras to the end.
I tried UTF-8 (recommended) and also UTF-16 and both worked!
You can also add characters from the character panel for testing (Panel on right in image).

You should not have null characters in your CSV; this is just plain text and should only have printable characters (no nulls or non printable ones).

Sample text:

Name,Latitude,Longitude,00Description,Category
Park Bench,43.6599,-79.3881,Great spot for a picnic.,Leisure
Googleplex,37.422,-122.0841,Google's corporate headquarters.,Technology Company
Apple Park,37.3317,-122.0053,Apple's corporate headquarters.,Technology Company
Empire State Building,40.7484,-73.9857,Iconic New York City Skyscraper.,Landmark

There is a learning curve to using NotePad++ but worth the investment in time.

This is one the the essential tools in my tool box:

I was able to successfully create CSV files for Google Maps and import these.

That was fun!

:)

1 Like

Thank you! I have never used NotePad ++. I will download it.
I think that you added the CFLF at the end of each line (?) and as the first characters of the line after the data. Is this correct?
BTW, what version of Notepad ++ do you suggest?

Make that CRLF, sorry

That is what was hidden and revealed with Notepad++:

I add a CRLF at end of text for testing.

I use the latest.

There is a learning curve to using Notepad++ !
I have been using it for decades and it is now just a tool.

I wanted to see if Processing generates the correct CSV as part of testing:

Table table;

void setup() {

  table = new Table();
  
// Name  Latitude  Longitude  Description  Category
  
  table.addColumn("Name", Table.STRING);
  table.addColumn("Latitude", Table.FLOAT);
  table.addColumn("Longitude", Table.FLOAT);
  table.addColumn("Description", Table.STRING);
  table.addColumn("Category", Table.STRING);
  
// Googleplex  37.422  -122.0841  Google's corporate headquarters.  Technology Company
    
  TableRow newRow = table.addRow();
  table.setString(0, "Name", "Googleplex");
  table.setFloat(0, "Latitude", 37.422);
  table.setFloat(0, "Longitude", -122.0841);
  table.setString(0, "Description", "Google's corporate headquarters.");
  table.setString(0, "Category", "Technology Company");
  
  saveTable(table, "data/new.csv");
}

It looked ok!

:)

1 Like

Yes, I did. I will try again with the CRLF as the first characters in a line following the last days line.

Here is an update. I made it work by creating a file that was exactly as long as it needed to be to hold the data. It seems as though the null characters at the end cause MyMaps to become upset.
I did this by creating another file (exact size) and then copied the data to it.
This seems cumbersome to me and I am wondering if there is an easier way to do it.

How are you currently creating these files?

If it is Processing code please share a minimal example.

:)

The following is the structure of the Mapping data:

//****** The MyMaps data file has the data required to make a Google Map
String MyMapsData = new String [1];
int MyMapsPointer = 0

β€œRecordCount” below points to the last record written out which is the number of
records.
The following is executed when all else has finished:

void MyMaps (int RecordCount){
String Title = β€œStation,LatLon,Name”;
String w = β€œβ€;
int i;
MyMapsData = new String [RecordCount];
MyMapsData[0] = Title;
for (i = 1; i < RecordCount; i++){
Tokens = Mapping_Data[i].split(β€œ,”);
w = Tokens[0] + β€œ,” + Tokens[3] + β€œ,” + Tokens[6];
MyMapsData[MyMapsPointer] = w;
MyMapsPointer ++;
}
saveStrings (MyMapsDataFileName,MyMapsData );
}

Hope this helps
Fred

Perhaps some additional information would help. In the preceding code, Latitude and Longitude are combined and separated by a comma, hence only one token for both.

Hi @fredstout ,

I think I found the issue!

I will share once you format your code:
https://discourse.processing.org/faq#format-your-code

Thanks in advance!

:)

I preformatted the entire sketch with Edit > Auto Format and it did.I can not find anything. The tabs at the top of the screen went blank. I added the backticks myself (I think), well here it is

β€˜β€™β€™
void MyMaps (int count){
String Title = β€œStation,Latitude,Longitude,Name”;
String w = β€œβ€;
int i;
int records = count -1;
MyMapsData = new String [count - 2];
MyMapsPointer = 1;
MyMapsData[0] = Title;
for (i = 2; i < records; i++){
Tokens = Mapping_Data[i].split(β€œ,”);
if (Tokens[0].equals(β€œEOF”)) break;
if (Tokens[1].equals(β€œMMX”)) Tokens[7] = "New MM "+str(int(Tokens[7])) + β€œ.0”;
w = Tokens[0] + β€œ,” + Tokens[3] + β€œ,” + Tokens[4] + β€œ,” + Tokens[7];
MyMapsData[MyMapsPointer] = w;
MyMapsPointer ++;
}
saveStrings (MyMapsDataFileName,MyMapsData );
}
β€˜β€™β€™
I hope this works. The Control E would not work.

Hello,

When code is properly formatted for posting it makes life easy for us!
I just click the copy button, past it and test it.
Unformatted code introduces all kinds of errors in the paste.

How to format code for posting:
https://discourse.processing.org/faq#format-your-code

This is an example of how code should be formatted for posting and what you should see:

Table table;

void setup() {

  table = new Table();
  
// Name  Latitude  Longitude  Description  Category
  
  table.addColumn("Name", Table.STRING);
  table.addColumn("Latitude", Table.FLOAT);
  table.addColumn("Longitude", Table.FLOAT);
  table.addColumn("Description", Table.STRING);
  table.addColumn("Category", Table.STRING);
  
// Googleplex  37.422  -122.0841  Google's corporate headquarters.  Technology Company
    
  TableRow newRow = table.addRow();
  table.setString(0, "Name", "Googleplex");
  table.setFloat(0, "Latitude", 37.422);
  table.setFloat(0, "Longitude", -122.0841);
  table.setString(0, "Description", "Google's corporate headquarters.");
  table.setString(0, "Category", "Technology Company");
  
  saveTable(table, "data/new.csv");
}

You can go back and edit your posts.

Keep trying!

:)