open a kml file in google maps

Keywords | open a kml file in google maps, open kml file google maps, how to open kml file, open kml file in google earth, kml file for google earth

What is a KML File in Google Maps

KML stands for Keyhole Markup Language. It is is an XML notation for expressing geographic annotation and visualization within Internet-based, 2d and 3d earth browsers. You can view kml on google maps javascript easily.

In this blog post, I will explain about KML files and how to open a KML file in google maps.

Open a KML File in Google Maps

To view KML on google maps you should serve your KML and KMZ files on public ip address. Some of my recommended techniques are:-

  • Create a folder and mark it for public access.
  • Use the Upload link to upload your KML files into this folder without conversion and shared with the world
  • Go to the Download link, copy it, and paste it into the Google Maps search box

Find the source code below:-

<html>
<head>
    <meta name="viewport" content="initial-scale=1.0">
    <meta charset="utf-8">
    <title>open a kml file in google maps</title>
    <style>
        /* Always set the map height explicitly to define the size of the div
       * element that contains the map. */
        #map {
            height: 570px;
        }
        /* Optional: Makes the sample page fill the window. */
        html, body {
            height: 100%;
            margin: 0;
            padding: 0;
        }
    </style>

    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
    <%-- <script async defer src="https://maps.googleapis.com/maps/api/js?key=YOURE_KEY&callback=initMap"></script>--%>

    <script>
        var map;
        function initMap() {
            var mapOptions = {
                zoom: 9, // google maps api zoom                                   
                center: new google.maps.LatLng(19.077006, 72.878427), // latitude and longitude map
                mapTypeId: google.maps.MapTypeId.ROADMAP   // google maps types | ROADMAP, TERRAIN & SATELLITE
            };
            map = new google.maps.Map(document.getElementById('map'), mapOptions);

            var ctaLayer = new google.maps.KmlLayer({
                url: 'http://googlemaps.github.io/js-v3-samples/cta.kml',
                map: map
            });
        }

        function RemovectaLayer() {
            if (ctaLayer) {
                ctaLayer.setMap(null);
                ctaLayer = null;
            }
        }

    </script>
</head>
<body onload="initMap();">    
        <h1>Open a KML File in Google Maps</h1>
        <div>
            <div id="map"></div>
        </div>    
</body>
</html>

Download Code

If you have a KML file from previous versions of Google Earth, you can view the saved places in Google Earth on web.

What do you think?

I hope you liked this article on open a kml file in google maps. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.

LEAVE A REPLY

Please enter your comment!
Please enter your name here