javascript - 如何在 Google map 中添加缩放控件

标签 javascript html google-maps google-api

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

 <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>

最佳答案

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

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

关于javascript - 如何在 Google map 中添加缩放控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39336231/

相关文章:

javascript - 谷歌地图可以设置为慢速恒平移吗?就像一场全局革命?

javascript - 如何在 Dreamhouse 示例应用程序安装中输入正确的 oauthurl?

javascript - 使用 jquery 自动滚动到可滚动弹出 div 的顶部

javascript - Qualtrics 表条件格式

javascript - Angular js 与 html 的行为不正确

Android Google API方向更新

javascript - 如何使用动态创建的 tr 元素迭代表

javascript - 我使用 php 创建了一个动态复选框,但是当我使用 .checked() 来检查它时,仅检查第一个单选按钮。剩下的怎么检查?

ios - 为什么以前缓存在 iPad 上的 SVG 图像并不总是从应用程序缓存中加载?

javascript - 在 javascript 中带有标签的多段线