提问者:小点点

更改Google地图位置,使标记位置不在中心


我想把我的谷歌地图(标记位置)改到右边

这是我的代码

        var uluru = {lat: 22.298337, lng: 114.174358};
            var map = new google.maps.Map(document.getElementById('map'), {
                zoom: 16,
                center: uluru
            });
            var image ="assets/images/marker.png";
            var marker = new google.maps.Marker({
                position: uluru,
                map: map,
                icon: image

            });

共1个答案

匿名用户

为地图中心使用一个单独的位置,调整该位置,使标记显示在您希望它显示的位置:

var map = new google.maps.Map(document.getElementById('map'), {
  zoom: 16,
  center: {lat: 22.298337, lng: 114.17}
});

代码段:

null

function initMap() {
  var uluru = {
    lat: 22.298337,
    lng: 114.174358
  };
  var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 16,
    center: {lat: 22.298337, lng: 114.17}
  });
  var marker = new google.maps.Marker({
    position: uluru,
    map: map,
  });
}
/* Always set the map height explicitly to define the size of the div
       * element that contains the map. */

#map {
  height: 100%;
}


/* Optional: Makes the sample page fill the window. */

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}
<!DOCTYPE html>
<html>

<head>
  <title>Simple Map</title>
  <script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>
  <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&callback=initMap&libraries=&v=weekly" defer></script>
  <!-- jsFiddle will insert css and js -->
</head>

<body>
  <div id="map"></div>
</body>

</html>