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 8937363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:24:01+00:00 2026-06-15T10:24:01+00:00

I am trying to make a site which uses different Fusion Tables. There is

  • 0

I am trying to make a site which uses different Fusion Tables. There is a dropdown menu which has several states. Each state has its own Fusion Table

I would like to make it so that when you pick a state, the map loads up that state’ Fusion Table.

How do I do that?

Below is my JavaScript code so far (filename is ‘script.js’). Below that is the HTML code.

When I change the state via dropdown, I’d like the map to load up the Fusion Table map of the state in the dropdown. Right now, it does not do that.

$(document).ready(function(){
    var states = {
        'Alabama':'3348442',
        'Alaska':'3370522'
    };
    // SECTION 1: ADDING HTML TO DOM
    var bodyDivs = [
        '<div id="map-canvas" />',
        '<div id="address-form-container" />',
        '<div id="state-select-container"><select id="state-select" /></div>'
    ];

    var addressContainer = [
        '<span id="form pretext"> Enter a city name or address </span>',
        '<input id="address" type="textbox" />',
        '<input type="button" value="Search" />'
    ];

    // Append the body to <html>
    $('html').append('<body />');
    for (var i=0; i<bodyDivs.length; i++){
        $('body').append(bodyDivs[i]);
    };

    // Append the address form to <body>
    for (var i=0; i<addressContainer.length; i++){
        $('div#address-form-container').append(addressContainer[i]);
    };

    // Append state names to the body
    for (var state in states){
        $('select').append('<option value='+state+'>'+state+'</option>');
    };
    // DONE ADDING HTML TO DOM


    // SECTION 2: Create the Google map with the coordinates and add the Fusion Tables layer to it. Plus, it zooms and centers to whatever state is selected.
    var geocoder;
    var gmap;
    var locationColumn = "'geometry'";
    var condition = "'Median income (dollars)'>0";
    var selectedState = document.getElementById("state-select").value;
    var tableId = states[selectedState];    
    var mapOptions = {
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    function initialize(){
        geocoder = new google.maps.Geocoder(); // This variables is used to automate zooming and centering in this script
        gmap = new google.maps.Map(document.getElementById("map-canvas"), mapOptions); // Removing this removes the Google Maps layer, but would keep any layers on top of it

        // The Fusion Tables layer variable
        var layer = new google.maps.FusionTablesLayer({
            query: {
                select: locationColumn,
                from: tableId,
                where: condition
            }
        });

        // This code snippet centers and zooms the map to the selected state.
        geocoder.geocode(
            {
                'address':selectedState
            },
            function(results,status){
                var sw = results[0].geometry.viewport.getSouthWest();
                var ne = results[0].geometry.viewport.getNorthEast();
                var bounds = new google.maps.LatLngBounds(sw,ne);

                gmap.fitBounds(bounds)
            }
        );

        layer.setMap(gmap);

        google.maps.event.addDomListener(selectedState,'change',function(){
            updateMap(layer,tableId,locationColumn);
        });         
    }


    // SECTION 3: Find the address once the button is clicked
    $(':button').click(
        function codeAddress(){
            var address = document.getElementById("address").value;

            geocoder.geocode(
                {
                    'address':address
                },
                function(results,status){
                    if(status===google.maps.GeocoderStatus.OK){
                        var addressSW = results[0].geometry.viewport.getSouthWest();
                        var addressNE = results[0].geometry.viewport.getNorthEast();
                        var bounds = new google.maps.LatLngBounds(addressSW,addressNE);

                        gmap.fitBounds(bounds);
                    } else {
                        alert("Couldn't find address for the following reason: " + status + ". Sorry about that. Please try another address.");
                    }
                }
            );
        }
    );


    function updateMap(layer,tableId,locationColumn){
        if (selectedState) {
            tableId = states[selectedState];

            layer.setOptions({
                query: {
                    select: locationColumn,
                    from: tableId,
                    where: condition
                }
            });

            geocoder.geocode(
                {
                    'address':selectedState
                },
                function(results,status){
                    var sw = results[0].geometry.viewport.getSouthWest();
                    var ne = results[0].geometry.viewport.getNorthEast();
                    var bounds = new google.maps.LatLngBounds(sw,ne);

                    gmap.fitBounds(bounds)
                }
            );          
        }
    }

    google.maps.event.addDomListener(window, 'load', initialize);
});

CSS:

#map-canvas {
height: 800px;
width: 1000px;

}

HTML code:

<html>
    <head>
        <meta charset="utf8">
        <title>TESTING THE MAPS</title>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
        <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
        <script type="text/javascript" src="public/js/script.js"></script>
    </head>
</html>

EDIT: Links to the HTML, CSS, and JS files—
http://speedy.sh/xRkZF/maptest.html
http://speedy.sh/zSt5p/script.js
http://speedy.sh/uCPxZ/style.css

  • 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-15T10:24:03+00:00Added an answer on June 15, 2026 at 10:24 am

    You have hardcoded selectedState, but you need to get the current value when the dropdown changes.

    Modify the change-listener to this:

    google.maps.event.addDomListener(document.getElementById('state-select'),
      'change',
      function(){
            updateMap(layer,this.value,locationColumn);
        });

    Now the 2nd argument passed to updateMap will be the selected state from the dropdown.
    Also modify updateMap, change the name of the 2nd argument to selectedState:

    
    

    function updateMap(layer,selectedState,locationColumn){
    //function code may stay as it is
    }

    Everything should work fine now.

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

Sidebar

Related Questions

Hey there, I'm trying to make a site which have following: News, Products, About
I'm developing a site which connects with Eway. I trying to make a Rebill
I'm trying to make a WordPress site that has six lists on a page,
I'm trying to make like buttons on my site which basically submit a form
I'm trying to make Cross Site Request using GWT Request builder, which i couldn't
I'm trying to make a comment section for my site. After a comment has
I'm trying to upgrade a Coldfusion8/MySQL site. The site has a complex search which,
i'm trying to make my site with a few languages. Every page includes config-file,
I'm trying to make my site respond correctly to the back button. I've saved
I am trying to make my site fully w3c validator compliant. At the moment,

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.