Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8714645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:38:54+00:00 2026-06-13T05:38:54+00:00

I am new to Google Maps. I have a Google Maps v3 map added

  • 0

I am new to Google Maps. I have a Google Maps v3 map added to an aspx file in an ASP.NET 4.0 project and am attempting to add toggle checkboxes for the four KML layers that I have on the map.

When I click on the checkbox, however, I get this error: “Microsoft JScript runtime error: Unable to get value of the property ‘setMap’: object is null or undefined”. Thank you!

Here is the HTML:

<body onload="initialize()">    
        <div id="map-canvas" style="width:100%; height:90%;"></div>
        <div id="legend">
            <div class="column">
                <input type="checkbox" id="landmarksLayer" onclick="toggleKMLLayer(this,'Notable Locations');" checked="checked" />Notable Locations (<img alt="yellow dot" src="Images/GoogleMaps/yellow-dot.png" />)
            </div>
        </div>
    </body>

Here is the Javascript:

    <%--Javascript--%>
    <script type="text/JavaScript" src="http://maps.googleapis.com/maps/api/js?key=[I_Removed_My_Key]&sensor=false"></script>

    <script type="text/javascript">

        var infowindow = new google.maps.InfoWindow({ "maxWidth": 100 });

        var map;

        var landmarksLayer;
        var publicArtLayer;
        var blueEmergencyPhonesLayer;
        var buildingsLayer;

        //toggle
        function toggleKMLLayer(chkbox, kmlLayerID) {

            //window.alert(kmlLayerID);

            if (chkbox.checked) {
                //window.alert("checked");
                landmarksLayer.setMap(map);
            }
            else {
                //window.alert("unchecked");
                landmarksLayer.setMap(null);
            }
        }

        function initialize() {

            var mapOptions = {
                center: new google.maps.LatLng(33.585737, -101.884804),
                zoom: 15,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };

            map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);

            var kmlLayerOptions = {
                preserveViewport: true,
                suppressInfoWindows: true
            };

            var landmarksLayer = new google.maps.KmlLayer('http://www.ttu.edu/map/points/landmarks.xml', kmlLayerOptions);
            landmarksLayer.setMap(map);

            var publicArtLayer = new google.maps.KmlLayer('http://www.ttu.edu/map/points/art.xml', kmlLayerOptions);
            publicArtLayer.setMap(map);

            var blueEmergencyPhonesLayer = new google.maps.KmlLayer('http://www.ttu.edu/map/points/emergency.xml', kmlLayerOptions);
            blueEmergencyPhonesLayer.setMap(map);

            var buildingsLayer = new google.maps.KmlLayer('http://www.ttu.edu/map/points/bldgs.xml', kmlLayerOptions);
            buildingsLayer.setMap(map);


            addKmlClickHandler(landmarksLayer);
            addKmlClickHandler(publicArtLayer);
            addKmlClickHandler(blueEmergencyPhonesLayer);
            addKmlClickHandler(buildingsLayer);
        }

        // create a new info window for the KML (outage) layer and the geo-coded house marker
        function addKmlClickHandler(KmlLayer) {
            google.maps.event.addListener(KmlLayer, "click", function (event) {
                infowindow.close();
                infowindow.setOptions({
                    pixelOffset: event.pixelOffset,
                    content: event.featureData.infoWindowHtml,
                    position: event.latLng
                });
                infowindow.open(map);
            });
        }

    </script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:38:56+00:00Added an answer on June 13, 2026 at 5:38 am

    You are creating global variables for your layers:

        var landmarksLayer;
        var publicArtLayer;
        var blueEmergencyPhonesLayer;
        var buildingsLayer;
    

    but you aren’t using them (inside your initialize function):

        var landmarksLayer = new google.maps.KmlLayer('http://www.ttu.edu/map/points/landmarks.xml', kmlLayerOptions);
        landmarksLayer.setMap(map);
    
        var publicArtLayer = new google.maps.KmlLayer('http://www.ttu.edu/map/points/art.xml', kmlLayerOptions);
        publicArtLayer.setMap(map);
    
        var blueEmergencyPhonesLayer = new google.maps.KmlLayer('http://www.ttu.edu/map/points/emergency.xml', kmlLayerOptions);
        blueEmergencyPhonesLayer.setMap(map);
    
        var buildingsLayer = new google.maps.KmlLayer('http://www.ttu.edu/map/points/bldgs.xml', kmlLayerOptions);
        buildingsLayer.setMap(map);
    

    The “var” in front of the variable there creates a new version of the variable that is local to the initialize function, leaving the global version uninitialized. You need the global version initialized so you can use it in your HTML click listener (which executes in the global context).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a map with a kmllayer that is added: ctaLayer = new google.maps.KmlLayer('http://www.npd.no/engelsk/cwi/pbl/en/aFactGlobe/disc/ActivityStatus_Producing_labels.kml');
I have a map object lile var map = new google.maps.Map(document.getElementById(map_canvas),myOptions); and I want
I have this block of code inside a loop: var points = [new google.maps.LatLng(lat1,
With google maps api (utlizing there new Places Library)Im trying to: Display a map
I am creating a map using the new(ish) v3 of the Google Maps API
I have a Google Map with some simple buttons added to pan to different
using jquery-ui-map here is my code $(document).ready(function() {$('#map_canvas').gmap({ 'center': new google.maps.LatLng(3.162456,21.09375), 'zoom': 2, 'streetViewControl':
i have a Google Map API v3 map that shows a kml layer added
I have a Google Map with a bunch of markers. I add markers to
I am using Google Maps API v3 , and have several map markers that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.