[GIS] How upload KML from your local disk using Google Maps API

google mapsgoogle-maps-apikml

I am trying to get load my KML from my local disk with given below code :

<script type="text/javascript">
     function initialize() {
    var mapOptions = {
      center: new google.maps.LatLng(43.321675,-75.172631),
      zoom: 8,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"),mapOptions);
    var ctaLayer = new google.maps.KmlLayer('C:/Users/Ashutosh_k/Downloads/newyork.kml');
    ctaLayer.setMap(map);
  }
</script>

Problem : When my google map is displaying its not showing up the elements of KML .

Best Answer

I don't think that it is possible to add local .kml files. The file needs to be stored at a location where the remote API is able to access it.

You have several choices as suggested here:

  1. Parse the kml file yourself. There are helpful libraries for that.
  2. Upload the kml file via Dropbox or Google Docs (see here)