Google maps 嵌入式Google SearchControl地图中的交通层

Google maps 嵌入式Google SearchControl地图中的交通层,google-maps,google-search-api,Google Maps,Google Search Api,如何在网页上的谷歌地图中激活交通层?地图是使用搜索控件创建的 <!-- ++Begin Map Search Control Wizard Generated Code++ --> <!-- // Created with a Google AJAX Search Wizard // http://code.google.com/apis/ajaxsearch/wizards.html --> <!-- // The Following d

如何在网页上的谷歌地图中激活交通层?地图是使用搜索控件创建的

<!-- ++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&v=2&key=ABQIAAAAxMICTqJZCQhVvaG5Z6vcbBQsQZTeCW4bnSEJHaQGIFLLp_Ev4hQzmbQjyOZxyLLe8CmaFaW5G3RI8g"
    type="text/javascript"></script>
  <script src="http://www.google.com/uds/api?file=uds.js&v=1.0&source=uds-msw&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++ -->

正在加载地图。。。
@导入url(“http://www.google.com/uds/css/gsearch.css");
窗口。_uds\u msw\u donotrepair=true;
@导入url(“http://www.google.com/uds/solutions/mapsearch/gsmapsearch.css");
.gsmsc mapDiv{
高度:400px;
}
.gsmsc idleMapDiv{
高度:400px;
}
#地图搜索{
宽度:700px;
保证金:1px;
填充:0px;
}
函数LoadMapSearchControl(){
变量选项={
zoomControl:GSmapSearchControl.ZOOM\u CONTROL\u ENABLE\u ALL,
标题:“,
url:“”,
idleMapZoom:GSmapSearchControl.ACTIVE\u MAP\u ZOOM+1,
activeMapZoom:GSmapSearchControl.ACTIVE\u MAP\u ZOOM+1
}
新的GSmapSearchControl(
document.getElementById(“mapsearch”),
"",
选择权
);
}
//安排在body.onload期间调用此函数
//事件处理
GSearch.setOnLoadCallback(LoadMapSearchControl);

当前无法通过API使用传输层。这个问题还有一个解决方案。

谷歌地图API将允许您访问地图,因此:

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); 
但要做到这一点,您需要渲染自己的一组过渡图块

顺便说一句,谷歌为自己的传输层使用的瓷砖是通过类似的方案检索的:

所以,你可以这样做:

var gTransitTileUrlTemplate = 'http://mlt1.google.com/mapslt?lyrs=transit&x={X}&y={Y}&z={Z}&w=256&h=256&gl=us&hl=en';
然而,这可能违反了MapsAPI的服务条款,并且不能保证Google不会更改此URL并破坏您的应用程序