Adding a Kml layer to google map

I am 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 definitely works, because if I change saveViewport to false, the map approaches the area defined by the KML layer.

But nothing appears, its layer itself is missing: /

Any ideas?

+6
source share
2 answers

Solved the problem at the end. The problem was that all this was done on a dev server, and I found out that in order to access KML files, they must be on a real site!

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

Thanks for the help:)

+5
source

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

If not, maybe something is wrong with your KML. It is possible, for example, for all functions to be established that visibility is disabled. A link to your KML will help you troubleshoot.

+2
source

Source: https://habr.com/ru/post/912490/


All Articles