famous58
famous58

Reputation: 5

Google Maps/Fusion Table infowindow on Address Query

I've created a Fusion map that shows polygon "zones" for an area (http://58design.com/gmaps/test.html). What I'd like to do is have a user input an address which will show that location on my map with an infowindow that has the same info as if the user clicked on the "zone". Basically I want something just like this (http://www.geocodezip.com/v3_collection-map2e_FT.html) but with my map/data.

I've found a couple older code examples but I can't seem to make it work with my map that I've created. Here is my current code:

<!DOCTYPE html>
    <html>
    <head>
    <meta name="viewport"></meta>
    <title>SCV Sheriff Reporting Districts - Google Fusion Tables</title>
    <style type="text/css">
    html, body, #googft-mapCanvas {
      height: 500px;
      margin: 0;
      padding: 0;
      width: 500px;
    }
    </style>

    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>

    <script type="text/javascript">
      function initialize() {
        google.maps.visualRefresh = true;
        var isMobile = (navigator.userAgent.toLowerCase().indexOf('android') > -1) ||
          (navigator.userAgent.match(/(iPod|iPhone|iPad|BlackBerry|Windows Phone|iemobile)/));
        if (isMobile) {
          var viewport = document.querySelector("meta[name=viewport]");
          viewport.setAttribute('content', 'initial-scale=1.0, user-scalable=no');
        }
        var mapDiv = document.getElementById('googft-mapCanvas');
        mapDiv.style.width = isMobile ? '100%' : '500px';
        mapDiv.style.height = isMobile ? '100%' : '500px';
        var map = new google.maps.Map(mapDiv, {
          center: new google.maps.LatLng(34.41269001087864, -118.55340000000001),
          zoom: 11,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        });
        map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(document.getElementById('googft-legend-open'));
        map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(document.getElementById('googft-legend'));

        layer = new google.maps.FusionTablesLayer({
          map: map,
          heatmap: { enabled: false },
          query: {
            select: "col2",
            from: "1uSGM1yPMJBlu74Znm4fPqdCsJjteB_kQ_nGz3tk",
            where: ""
          },
          options: {
            styleId: 2,
            templateId: 2
          }
        });

        if (isMobile) {
          var legend = document.getElementById('googft-legend');
          var legendOpenButton = document.getElementById('googft-legend-open');
          var legendCloseButton = document.getElementById('googft-legend-close');
          legend.style.display = 'none';
          legendOpenButton.style.display = 'block';
          legendCloseButton.style.display = 'block';
          legendOpenButton.onclick = function() {
            legend.style.display = 'block';
            legendOpenButton.style.display = 'none';
          }
          legendCloseButton.onclick = function() {
            legend.style.display = 'none';
            legendOpenButton.style.display = 'block';
          }
        }
      }

      google.maps.event.addDomListener(window, 'load', initialize);
    </script>
    </head>

<body>
  <div id="googft-mapCanvas"></div>
</body>
</html>

Upvotes: 0

Views: 555

Answers (1)

geocodezip
geocodezip

Reputation: 161334

Starting from the code in the example you reference

  1. change FusionTableID to be that of your table

    var FusionTableID = '1uSGM1yPMJBlu74Znm4fPqdCsJjteB_kQ_nGz3tk';
    
  2. change the GViz query of the table to use the correct column names

    var queryText ="SELECT 'name', 'Zone Area'  FROM "+FusionTableID+" WHERE ST_INTERSECTS(\'Zone Area\', CIRCLE(LATLNG(" + point.toUrlValue(6) + "),0.5));";
    
  3. change the FusionTables layer to use the new syntax for encrypted ids.

    layer = new google.maps.FusionTablesLayer({query:{from:FusionTableID},suppressInfoWindows:true});
    

working example

Upvotes: 1

Related Questions