Google Map - Load KML Overlay

David P

I am trying to display a map, zoom into a zipcode, and then place Congressional District overlay onto map. The overlay is here: https://www.google.com/fusiontables/DataSource?snapid=S506424n-DY

I downloaded the KML link file, and saved it onto my local IIS server. However, the overlay never is drawn.

I also added the following mime types to my IIS Server:

.kml application/vnd.google-earth.kml+xml 
.kmz application/vnd.google-earth.kmz

The kml file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<NetworkLink>
<name><![CDATA[2012 US Congressional Districts]]></name>
<Link>
<href>
https://www.google.com/fusiontables/exporttable?query=select+col5+from+1QlQxBF17RR-89NCYeBmw4kFzOT3mLENp60xXAJM&amp;o=kmllink&amp;g=col5</href>
</Link>

My HTML/javascript looks like:

<script src="http://maps.googleapis.com/maps/api/js" type="text/javascript"></script>
<script language="javascript">
var map;
var marker;
function showAddress() {
    $("#divGoogleMap").css('display', '');
    var mapProp = {
        center: new google.maps.LatLng(51.508742, -0.120850),
        zoom: 11,
        mapTypeId: google.maps.MapTypeId.TERRAIN
    };
    map = new google.maps.Map(document.getElementById("divGoogleMap"), mapProp);

    myListener = google.maps.event.addListener(map, 'click', function (event) {
        placeMarker(event.latLng);
    });
    google.maps.event.addListener(map, 'drag', function (event) {
        placeMarker(event.latLng);
    });

    var zipCode = $("#txtZip").val();
    var geocoder = new google.maps.Geocoder();
    geocoder.geocode({ 'address': zipCode }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            //Got result, center the map and put it out there
            var pos = results[0].geometry.location;
            saveLocation(pos);
            map.setCenter(pos);
            marker = new google.maps.Marker({
                map: map,
                draggable: true,
                position: pos
            });
        } else {
            alert("Geocode was not successful for the following reason: " + status);
        }
    });
    var kmlUrl = '/DesktopModules/HelloWorld/2012_US_Congressional_Districts.kml';
    var kmlOptions = {
        suppressInfoWindows: true,
        preserveViewport: false,
        map: map
    };
    var kmlLayer = new google.maps.KmlLayer(kmlUrl, kmlOptions);

}
function placeMarker(location) {
    if (marker) {
        marker.setPosition(location);
    } else {
        marker = new google.maps.Marker({
            position: location,
            map: map,
            draggable: true
        });
        google.maps.event.addListener(marker, "drag", function (mEvent) {
            populateInputs(mEvent.latLng);
        });
    }
    saveLocation(location);
}
function saveLocation(pos) {
    $("#hfLatitude").val(pos.lat());
    $("#hfLogitude").val(pos.lng());
}
</script>

<table cellpadding="2" cellspacing="2" border="0">
    <tr>
        <td>
            <asp:TextBox ID="txtZip" ClientIDMode="Static" runat="server"></asp:TextBox>
        </td>
        <td>
            <input type="button" id="btnSearch" value="Search" onclick="showAddress()" />
        </td>
    </tr>
</table>
<div id="divGoogleMap" style="width: 800px;height: 600px;display: none;"></div>
<asp:HiddenField ID="hfLatitude" ClientIDMode="Static" runat="server" />
<asp:HiddenField ID="hfLongitude" ClientIDMode="Static" runat="server" />

What am I doing wrong here?

scaisEdge

For use in google maps th kml must be located in an accessible server e not in local.

This is form google doc.

Overview

The Google Maps API supports the KML and GeoRSS data formats for displaying geographic information. These data formats are displayed on a map using a KmlLayer object, whose constructor takes the URL of a publicly accessible KML or GeoRSS file.

the constructor take the URL of a publicly accessible KML.

Then for yoour need you must place your kml in a publicly accessible server

I had forgotten that i had already had a similar experience some years ago and the solution was precisely to place the files kml on a server accessible from the Internet.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Click event on KML region within Google Map

Android google map overlay on top

Angular google maps uploaded KML Layer is not showing up on google map:

how to load the kml file into google earth using python

Google map is not load

Google map failed to load

How to overlay bar charts on a google map?

Create Overlay ImageView Animation Google Map

React-google-maps: How do I create a clickable kml map that shows me meta data of the kml?

KML Points Can't Display on Android Google Map

Draw kml layer on google map from a text area

How to import a KML polygon file in google map fragment android studio

Google map kml with 2 points and descriptions but same description displays for both

Google Map on Android do not load

Image not load in Google map marker

KML Layer not displaying on Map

Display KML file in the map

Can you overlay clickable shapes over a google map for display on website

How to add a button and overlay it on my Google map fragment

google-map-api3 how to remove an overlay using prototype

Stop event propagation in JavaScript overlay menu to Google map

Overlay Image covers marker in customized Google Map Web

How choose image size for adding own Overlay in google map api?

make layout that overlay above google map fragment in android

How To Open a Map Overlay on Marker Click in Google Maps

Google Maps mangling KML

Any way I can load KML data from Google maps (again) via JS API?

Error data may still loading in map google maps fusion tables kml querying geometry

javascript does not display current location of user over a google map using KML layer?