Google Fusion Tables API

Fusion Tables Layer Example: Driving Directions


<!DOCTYPE html>
<!--
  Copyright 2011 Google Inc. All Rights Reserved.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="UTF-8">

    <title>Fusion Tables Layer Example: Driving Directions</title>

    <link href="/apis/fusiontables/docs/samples/style/default.css"
        rel="stylesheet" type="text/css">
    <script type="text/javascript"
        src="http://maps.google.com/maps/api/js?sensor=false"></script>

    <style type="text/css">
      #map-canvas {
        float: left;
      }

      #results {
        width: 350px;
        float: left;
        margin-left: 10px;
      }
    </style>

    <script type="text/javascript">

      function initialize() {

        var map = new google.maps.Map(document.getElementById('map-canvas'), {
          mapTypeId: google.maps.MapTypeId.ROADMAP,
          center: new google.maps.LatLng(37.5, -122.1),
          zoom: 10
        });

        var infoWindow = new google.maps.InfoWindow();

        var directionsDisplay = new google.maps.DirectionsRenderer();
        directionsDisplay.setMap(map);
        directionsDisplay.setPanel(document.getElementById('results'));

        var directionsService = new google.maps.DirectionsService();

        var layer = new google.maps.FusionTablesLayer({
          query: {
            select: 'Location',
            from: '1ejXvdpkrru4MAssBa90SF5O9jhl4a6CdES8bbg'
          },
          map: map,
          options: {
            suppressInfoWindows: true
          }
        });

        // Add a click listener to the layer that creates a new infowindow
        // with directions text input
        google.maps.event.addListener(layer, 'click', function(e) {
          infoWindow.setContent(e.infoWindowHtml +
              '<br><label>Get Directions to here:</label> ' +
              '<input type="text" id="begin">' +
              '<input type="button" value="go" id="go">');
          infoWindow.setPosition(e.latLng);
          infoWindow.open(map);

          google.maps.event.addDomListener(document.getElementById('go'),
              'click', function() {
                var start = document.getElementById('begin').value;

                var request = {
                  origin: start,
                  destination: e.latLng,
                  travelMode: google.maps.DirectionsTravelMode.DRIVING
                };
                directionsService.route(request, function(response, status) {
                  if (status == google.maps.DirectionsStatus.OK) {
                    directionsDisplay.setDirections(response);
                  } else {
                    window.alert('Error generating directions: ' + status);
                  }
                });
          });
        });
      }

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

    </script>
  </head>

  <body>
    <div id="map-canvas"></div>
    <div id="results"></div>
  </body>
</html>

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.