【问题标题】:Zoom doesn't work when directions are set google maps v3设置方向时缩放不起作用谷歌地图 v3
【发布时间】:2012-09-05 20:58:40
【问题描述】:

希望有人能帮我解决这个问题,我试图通过缩放和居中显示两个方向点,这样我就可以只显示 2 个点而不是所有地图!看来缩放不起作用。

这是我的代码

       var map;
        function initialize(){                  
                  var mapOptions = {
                  zoom: 14,
                  disableDefaultUI: true,
                  mapTypeId: google.maps.MapTypeId.ROADMAP
                };

                map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);


                var request = {
                        origin:"Mexico",
                        destination:"Montreal",
                        travelMode: google.maps.TravelMode.DRIVING
                };

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

                // Indicamos dónde esta el mapa para renderizarnos
                directionsDisplay.setMap(map);

                directionsService.route(request, function(result, status) {
                    if (status == google.maps.DirectionsStatus.OK) {
                      directionsDisplay.setDirections(result);
                    }
                  }); 
        }

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

提前致谢

【问题讨论】:

    标签: maps zooming directions


    【解决方案1】:

    解决您的问题更改:

    disableDefaultUI: true, 
    

    disableDefaultUI: false,
    

    来自 [Google Maps API]:https://developers.google.com/maps/documentation/javascript/controls#DisablingDefaults

    您可能希望关闭 API 的默认 UI 设置。去做 因此,设置地图的 disableDefaultUI 属性(在地图选项中 对象)为真。 此属性禁用任何自动 UI 行为 Google Maps API。

    如果您仍想禁用 UI 元素,您可能应该单独执行它们。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-05
      • 1970-01-01
      • 1970-01-01
      • 2013-09-17
      相关资源
      最近更新 更多