【问题标题】:Disable InfoWindow in Google Maps在 Google 地图中禁用 InfoWindow
【发布时间】:2012-09-17 22:53:06
【问题描述】:

您好,您是否在我的谷歌地图上禁用了 Google 信息窗口,正如您通过访问 http://harpers.everythingcreative.co.uk/contact 看到的那样,信息窗口看起来很奇怪并且显示的地址不正确。

    // ---------- Geolocation ----------    
function fallback() {
            var myOptions = {
            center: new google.maps.LatLng(51.43255949795703, -0.461750328540802),
            zoom: 14,
            mapTypeId: google.maps.MapTypeId.ROADMAP
            };

            var map = new google.maps.Map(document.getElementById("Map_Canvas"),
            myOptions);

            var markerPos = new google.maps.LatLng(51.43255949795703, -0.461750328540802);
            var marker = new google.maps.Marker({
            position: markerPos,
            map: map,
            title: "The Harpers Hairdressing"
            });
            }

   function initGeolocation() 
    { 
           if(navigator.geolocation) 
            { 
              // Call getCurrentPosition with success and failure callbacks 
              navigator.geolocation.getCurrentPosition( success, fail ); 
            } 
        else 
            { 
              fallback()
               } 
    } 
    var directionDisplay; 
    var directionsService = new google.maps.DirectionsService(); 
    var map; 
    function success(position) { 
      directionsDisplay = new google.maps.DirectionsRenderer(); 
      coords = new google.maps.LatLng(position.coords.latitude, 
position.coords.longitude); 
      var myOptions = { 
        zoom:12, 
        mapTypeId: google.maps.MapTypeId.ROADMAP, 
        center: coords 
      } 
      map = new google.maps.Map(document.getElementById("Map_Canvas"), 
myOptions); 
      directionsDisplay.setMap(map);
      calcRoute();
    } 
    function calcRoute() { 
      var start = coords; 
      var end = new google.maps.LatLng(51.43255949795703, -0.461750328540802); 
      var request = { 
        origin:start, 
        destination: "3 Fir Tree Place, Church Road, Ashford, Middlesex, TW15 2PH",
        travelMode: google.maps.TravelMode.DRIVING,
      }; 
      directionsService.route(request, function(result, status) { 
        if (status == google.maps.DirectionsStatus.OK) { 
          directionsDisplay.setDirections(result); 
        } 
      }); 
    } 
        function fail() 
        { 

           fallback();

} 

如您所见,后备是一个简单的标记,它不显示和信息窗口,但方向显示。

【问题讨论】:

    标签: javascript html google-maps geolocation


    【解决方案1】:

    在您的 DirectionsRenderer 对象上,您可以传入一个 DirectionsRendererOptions 选项结构。其中有一个 markerOptions 值,您应该能够使用它来解除标记与地图的关联。

    这样的事情可能会奏效:

    directionsDisplay = new google.maps.DirectionsRenderer({
      markerOptions : {
            map: null,  //  you probably would only need 1 or the other of these two values
            visible: false
      }
    }); 
    

    【讨论】:

    • 那一半修复了它,因为它完全隐藏了标记而不是 infoWindow
    【解决方案2】:

    在图层选项中使用 suppressInfoWindows:true:

    layer = new google.maps.FusionTablesLayer({
            map: map,
            heatmap: {
                enabled: false
            },
            options: {
                suppressInfoWindows:true
            }
        });
    

    【讨论】:

      【解决方案3】:

      使用 duncan 的修复程序,我只使用了 clickable:false 选项,它似乎可以解决问题,非常感谢!

          directionsDisplay = new google.maps.DirectionsRenderer({
              markerOptions : {
                  visible: true,
                  clickable: false
              }
        }); 
      

      【讨论】:

        猜你喜欢
        • 2014-01-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-14
        • 2014-07-10
        • 2014-01-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多