Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Kml Layer to google map

I'm trying to add a couple of KML layers to a map. This is the code I have:

    var myKmlOptions = {
        preserveViewport: true,
        suppressInfoWindows: true
    }

    var kmlLayer_1 = new google.maps.KmlLayer("Layers/layer1.kml", myKmlOptions);
    var kmlLayer_2 = new google.maps.KmlLayer("Layers/layer2.kml", myKmlOptions);
    kmlLayer_1.setMap(map);
    kmlLayer_2.setMap(map);

Something is definately working because if I change preserveViewport to false, the map zooms closer into the area defined by the KML Layer.

But nothing is showing up, the layer its self is missing :/

Any ideas?

like image 878
Ross Coulbeck Avatar asked Apr 05 '12 11:04

Ross Coulbeck


People also ask

Can you add custom layers to Google Maps?

Open or create a map. You'll see your layers in the box on the left. Make the changes you want. Add a layer: Click Add layer.

Can I view a KML file in Google Maps?

You can view most simple KML files with Google Earth for Chrome (version 9) or in the Google Earth app on your mobile device. If you're unable to view complex KML files, use Google Earth for desktop (version 7), which supports all KML features.

Can you load a KMZ file in Google Maps?

kmz (Zipped KML format) file in your browser. Free online tool to view KML, KMZ files from the web on a Google map. You can open KML, KMZ files from URL, Google Drive or from your computer.


2 Answers

Solved the problem in the end. The problem was that this was all being done on a dev server and I learnt that for google to access the KML files they need to be on a live site!

Temporarily put them on another live site to reference while I'm still working on development.

Thanks for help :)

like image 199
Ross Coulbeck Avatar answered Oct 23 '22 14:10

Ross Coulbeck


Does your layer display at http://maps.google.com?q=http://your.site/your.kml ?

If not, there's probably something wrong with your KML. Perhaps, for example, all the features are set to visibility being off. A link to your KML would help troubleshooting.

like image 29
jlivni Avatar answered Oct 23 '22 14:10

jlivni