1

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 .

4

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)
  • Actually i have some data which i cannot put on cloud .I am struggling since last couple of days . is there any way i keep my data in house and use google map and KML overlay as well my deadline donot permits me to explore other ways . – bhalkian Nov 25 '12 at 5:48
  • you can parse the kml yourself. you can use the read method from the OpenLayers KML format to get a list of features (dev.openlayers.org/releases/OpenLayers-2.7/doc/apidocs/files/…) Then you might be able to draw those features onto your map. I have never tried this, but it seems this would be your way to go then This question is maybe related: gis.stackexchange.com/questions/16629/… – Martin Nov 25 '12 at 14:29
0

I do agree with Martin's point that you cannot just load KML file from your local drive...

However, you can always create a google site by using your google account, and then use that site to host your kml file.

Here is a very useful/detailed documentation shows you how to do it step by step.

Hope it answered your question.

0

Why don't you use Google Fusion Tables for this? Simply create a new fusion table, upload the KML, when prompted, and use a Fusion Tables Layer to display it on a Google map! You can find details on how to use a Fusion Tables Layer in the API doc here: Fusion Tables Layer doc

Below, you can find a sample from the documentation linked above:

var chicago = new google.maps.LatLng(41.850033, -87.6500523);

map = new google.maps.Map(document.getElementById('map_canvas'), {

center: chicago,

zoom: 12,

mapTypeId: 'roadmap' });

var layer = new google.maps.FusionTablesLayer({

query: {

select: 'Geocodable address',

from: '1mZ53Z70NsChnBMm-qEYmSDOvLXgrreLTkQUvvg' }

});

layer.setMap(map);

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.