javascript 如何改变谷歌MapJS API中Map和卫星按钮的位置?

xggvc2p6  于 2023-03-06  发布在  Java
关注(0)|答案(1)|浏览(117)

我想把这个简单的谷歌Map代码左上角的satellite-map按钮移到右上角,但是我不知道怎么做。
你能帮帮我吗?

    • HTML**
<h3>My Google Maps Demo</h3>
<div id="map"></div>
<!-- Replace the value of the key parameter with your own API key. -->
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&callback=initMap"></script>
    • 日本**
var map;
function initMap() {
  map = new google.maps.Map(document.getElementById('map'), {
    center: {lat: -34.397, lng: 150.644},
    zoom: 8
  });
}
    • css**(不需要)
#map {
  height: 100%;
}
html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}
dwbf0jvd

dwbf0jvd1#

我认为您需要"mapTypeControlOptions"并设置"位置"

function initMap() {
  var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 8,
    center: {lat: -34.397, lng: 150.644},
    mapTypeControl: true,
    mapTypeControlOptions: {
      style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR,
      position: google.maps.ControlPosition.TOP_RIGHT
    },
    zoomControl: true,
    zoomControlOptions: {
      position: google.maps.ControlPosition.LEFT_CENTER
    },
    scaleControl: true,
    streetViewControl: true,
    streetViewControlOptions: {
      position: google.maps.ControlPosition.TOP_LEFT
    }
 });
}

参见:https://developers.google.com/maps/documentation/javascript/controls

相关问题