0

I am trying to load data for a Marker from a csv file and I am using the GeoCSV plugin for that.

I downloaded the js file and added it to my code and also created a csv file in Excel which looks like this:

enter image description here

The resulting csv file:

lat;lng;title
52;8;test
8;52;test2
;;
;;
;;
;;
;;

But the two markers dont appear on the map. I think this is because of how I try to load in and add the data. I tried using the default example from github and also experimented with the linked examples from github.

My current code:

 (function() {                                                                             
 'use strict';            
  var map = L.map('mapContainer');   
  $.get('test.csv', function(csvContents) {
  var geoLayer = L.geoCsv(csvContents, {firstLineTitles: true, fieldSeparator: ','});
  map.addLayer(geoLayer);
  });
  });
4
  • Change option fieldSeparator: ',' to fieldSeparator: ';'.
    – TomazicM
    Jul 20 at 8:39
  • Nope, I still have the same issue.
    – CLa
    Jul 20 at 9:00
  • Did you clear the browser cache? Any errors in the browser debugger console?
    – TomazicM
    Jul 20 at 9:32
  • Yes, just cleared the cache and nothing changed. Also no errors in the console.
    – CLa
    Jul 20 at 9:48

1 Answer 1

1

There are two problems in your code that prevent display of markers.

First problem is that delimiter in your CSV file is ;, not ,, so your separator defining option should be fieldSeparator: ';'.

Second problem is that in your code you define function but never execute it, since there is () missing at the end to execute it.

Code should then look like this (tested):

(function() {                                                                             
  'use strict';            
  $.get('data/test-csv.txt', function(csvContents) {
    var geoLayer = L.geoCsv(csvContents, {firstLineTitles: true, fieldSeparator: ';'});
    map.addLayer(geoLayer);
  });
})();
2
  • Thanks for the help, but now my access to the file is being blocked by CORS policy :( . Do you have an idea how to fix that?
    – CLa
    Jul 20 at 10:44
  • Answer above is solution for the problem from your question. It's customary on GIS SE site to mark it as accepted, to let others with similar problems know that problem from question was resolved. If you have another problem/question, please post it as a separate question.
    – TomazicM
    Jul 20 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.