【问题标题】:How to add Zoom controls in Google Map如何在谷歌地图中添加缩放控件
【发布时间】:2016-09-05 18:53:08
【问题描述】:

我想在我的谷歌地图右下角显示放大(+)和缩小选项(-)。我试过了,但我没有得到缩放选项。

 <script async defer
            src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDQ2&callback=initMap">
    </script>
  <script type="text/javascript">
        window.onload = function () {
            var mapOptions = {
                center: new google.maps.LatLng(17.44633567526379, 78.38290556613924),
                zoom: 14,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            var infoWindow = new google.maps.InfoWindow();
            var latlngbounds = new google.maps.LatLngBounds();
            var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
            google.maps.event.addListener(map, 'click', function (e) {
                alert("Latitude: " + e.latLng.lat() + "\r\nLongitude: " + e.latLng.lng());
                document.getElementById("txtLongitude").value = e.latLng.lng();
                document.getElementById("txtLatitude").value = e.latLng.lat();
            });
        }
    </script>
    <div id="dvMap" style="width: 700px; height: 300px">
    </div>

【问题讨论】:

标签: javascript html google-maps google-api


【解决方案1】:

在您的 MapOptions 中添加 zoomControl: true,如下所示:

var mapOptions = {
                center: new google.maps.LatLng(17.44633567526379, 78.38290556613924),
                zoomControl: true,
                zoom: 14,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 2012-06-25
    • 2012-03-14
    • 1970-01-01
    • 1970-01-01
    • 2012-02-11
    • 1970-01-01
    相关资源
    最近更新 更多