标记定位错误,某些选项被禁用

Marker mislocated with certain option disabled

本文关键字:选项 定位 错误      更新时间:2023-09-26

尝试在使用optimized: false选项时使用Maps JS API放置标记。这导致该标记被放置在哈萨克斯坦,而不是挪威。如果缩放到缩放级别0(世界缩放),则标记将重新定位到其预期位置。有线索吗?

JsFiddle

var mapOptions = {
    zoom: 5.4,
    center: new google.maps.LatLng(72.84664426123108, -32.280699735104044) // norway
};
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
marker = new google.maps.Marker({
    position: new google.maps.LatLng(64.426895, 11.496360),
    map: map,
    optimized: false
});

zoom必须为整数。zoom: 5.4不工作

更新的小提琴

代码片段:

var map = null;
var marker = null;
$(document).ready(function() {
  var mapOptions = {
    zoom: 5,
    center: new google.maps.LatLng(72.84664426123108, -32.280699735104044) // norway
  };
  map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
  marker = new google.maps.Marker({
    position: new google.maps.LatLng(64.426895, 11.496360),
    map: map,
    optimized: false
  });
  map.setCenter(marker.getPosition());
});
body,
html,
#map-canvas {
  height: 100%;
  overflow: hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3"></script>
<div id="map-canvas"></div>