3

I am trying to load a local KML file to the map for this I am using FileReader object (File API). To use google.maps.KmlLayer I need to use readAsDataURL to transform to a URL the file, the problem is that KML File is not loading to the map and I don't get any error. I think may be url attribute in KmlLayer doesn't accept data url.

This is the code:

gp.addEventListeners = function(){
  $("#file-upload").change(function (evt){
      var file  = evt.target.files[0]; // FileList object
      var reader = new FileReader();

      reader.onloadend = function () {
         var ctaLayer = new google.maps.KmlLayer({
          url: reader.result
        });
        ctaLayer.setMap(gp.map);
      }

      if (file) {
        reader.readAsDataURL(file);
      }     
  });
}

In OpenLayes the same code is working.

What I can do? I need help :(

Sorry for my English.

-1

Save the file in server then get the fullpath of the file. Assign fullpath to KmlLayer constructor

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.