views:

462

answers:

2

How can I activate the Transit layer in a Google Map on a web page? The map is created using the search control.

<!-- ++Begin Map Search Control Wizard Generated Code++ -->
  <!--
  // Created with a Google AJAX Search Wizard
  // http://code.google.com/apis/ajaxsearch/wizards.html
  -->

  <!--
  // The Following div element will end up holding the map search control.
  // You can place this anywhere on your page
-->
  <div id="mapsearch">
    <span style="color:#676767;font-size:11px;margin:1px;padding:0px;">Loading map ...</span>
  </div>

  <!-- Maps Api, Ajax Search Api and Stylesheet
  // Note: If you are already using the Maps API then do not include it again
  //       If you are already using the AJAX Search API, then do not include it
  //       or its stylesheet again
  //
  // The Key Embedded in the following script tags is designed to work with
  // the following site:
  -->
  <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAxMICTqJZCQhVvaG5Z6vcbBQsQZTeCW4bnSEJHaQGIFLLp_Ev4hQzmbQjyOZxyLLe8CmaFaW5G3RI8g"
    type="text/javascript"></script>
  <script src="http://www.google.com/uds/api?file=uds.js&amp;v=1.0&amp;source=uds-msw&amp;key=ABQIAAAAxMICTqJZCQhVvaG5Z6vcbBQsQZTeCW4bnSEJHaQGIFLLp_Ev4hQzmbQjyOZxyLLe8CmaFaW5G3RI8g"
    type="text/javascript"></script>
  <style type="text/css">
    @import url("http://www.google.com/uds/css/gsearch.css");
  </style>

  <!-- Map Search Control and Stylesheet -->
  <script type="text/javascript">
    window._uds_msw_donotrepair = true;
  </script>
  <script src="http://www.google.com/uds/solutions/mapsearch/gsmapsearch.js?mode=new"
    type="text/javascript"></script>
  <style type="text/css">
    @import url("http://www.google.com/uds/solutions/mapsearch/gsmapsearch.css");
  </style>

  <style type="text/css">
    .gsmsc-mapDiv {
      height : 400px;
    }

    .gsmsc-idleMapDiv {
      height : 400px;
    }

    #mapsearch {
      width : 700px;
      margin: 1px;
      padding: 0px;
    }
  </style>
  <script type="text/javascript">
    function LoadMapSearchControl() {

      var options = {
            zoomControl : GSmapSearchControl.ZOOM_CONTROL_ENABLE_ALL,
            title : "<?php echo $city. ','. $country; ?>",
            url : "",
            idleMapZoom : GSmapSearchControl.ACTIVE_MAP_ZOOM+1,
            activeMapZoom : GSmapSearchControl.ACTIVE_MAP_ZOOM+1
            }

      new GSmapSearchControl(
            document.getElementById("mapsearch"),
            "<?php echo $city. ','. $country; ?>",
            options
            );
    }
    // arrange for this function to be called during body.onload
    // event processing
    GSearch.setOnLoadCallback(LoadMapSearchControl);
  </script>
<!-- ++End Map Search Control Wizard Generated Code++ -->
+1  A: 

The Transit layer is currently not available via the API. There is an Enhancement Request open for this issue.

Cannonade
+1  A: 

The Google Maps API will let you add a tile overlay to your map, thusly:

var tileLayerOverlay = new GTileLayerOverlay(
  new GTileLayer(null, null, null, {
    tileUrlTemplate: 'http://example.com/transit_tiles/{Z}_{X}_{Y}.png', 
    isPng:true,
    opacity:1,
  })
);

map.addOverlay(tileLayerOverlay);

But to do that you'd need to have rendered your own set of transit tiles.

Incidentally, the tiles Google uses for its own transit layer are retrieved via a similar scheme:

http://mlt2.google.com/mapslt?lyrs=transit&amp;x=1310&amp;y=3166&amp;z=13&amp;w=256&amp;h=256&amp;gl=us&amp;hl=en

So, you could do this:

var gTransitTileUrlTemplate = 'http://mlt1.google.com/mapslt?lyrs=transit&amp;x={X}&amp;y={Y}&amp;z={Z}&amp;w=256&amp;h=256&amp;gl=us&amp;hl=en';

However, this may violate the Maps API's Terms of Service, and there is no guarantee that Google will not change this URL and break your application.

tcarobruce