[英]Change Google Map position so that the marker location is not in the center
我想将我的谷歌 map(标记位置)更改为右侧
当前标记位置:
我想在这里标记位置:
这是我的代码
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
});
为 map 中心使用一个单独的位置,调整它以便标记出现在您想要的位置:
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 16,
center: {lat: 22.298337, lng: 114.17}
});
代码片段:
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.