我正在使用绘图管理器,如果地图位于屏幕的顶部/左侧位置工作完美,但是当地图处于其他位置时,绘图管理器绘制线但有一种奇怪的行为,“下一个位置点“不在鼠标指针所在的中心位置。
见图:
var lat = 40.4167754;
var lng = -3.7037901;
var mapOptions, map, maker, drawingManager;
function initialize() {
mapOptions = {
center: { lat: lat, lng: lng },
zoom: 13
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
maker = new google.maps.Marker({
position: { lat: lat, lng: lng },
map: map
});
drawingManager = new google.maps.drawing.DrawingManager({
drawingMode: google.maps.drawing.OverlayType.POLYLINE,
drawingControl: true,
drawingControlOptions: {
position: google.maps.ControlPosition.TOP_CENTER,
drawingModes: [
google.maps.drawing.OverlayType.CIRCLE,
google.maps.drawing.OverlayType.POLYLINE
]
},
circleOptions: {
fillColor: '#ffff00',
fillOpacity: 1,
strokeWeight: 5,
clickable: false,
editable: true,
zIndex: 1
}
});
drawingManager.setMap(map);
}
function loadScript() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp' +
'&libraries=geometry,visualization,drawing&signed_in=true&callback=initialize&key=XXX';
document.body.appendChild(script);
}
$(document).ready(function(){
loadScript();
});
答案 0 :(得分:0)
问题是由于js版本。版本3完美运行,而不是3.exp
script.src = 'https://maps.googleapis.com/maps/api/js?v=3' +
'&libraries=geometry,visualization,drawing&signed_in=true&callback=initialize&key=XXX';