简体   繁体   English

更改谷歌 Map position 使标记位置不在中心

[英]Change Google Map position so that the marker location is not in the center

I want to change my google map (marker position) to right我想将我的谷歌 map(标记位置)更改为右侧

current marker location:当前标记位置: current marker location

I want marker location here:我想在这里标记位置: I want marker location here

here is my code这是我的代码

        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

            });

Use a separate location for the map center, adjust that so the marker appears where you want it to:为 map 中心使用一个单独的位置,调整它以便标记出现在您想要的位置:

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

结果地图的屏幕截图

code snippet:代码片段:

 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM