添加标记时遇到问题。
var marker = new google.maps.Marker({
position: myLatlng,
title:"Hello World!"
});
// To add the marker to the map, call setMap();
marker.setMap(map);
https://jsfiddle.net/73ogq84a/
简单的例子,每一秒我都会放置标记,页面不会重新加载,但会重新加载一些布局,我们会看到 map 重新加载的效果。
可以顺利地放置标记。
但是在这个页面http://www.flightradar24.com/simple_index.php一切正常,飞机正在飞行, map 重新加载没有影响。
最佳答案
使标记和 map 全局化。不要每次都重新创建 map ,只需移动标记即可。
var map, marker, myLatlng;
setInterval(function () {
if (!marker || !marker.setPosition) {
marker = new google.maps.Marker({
position: myLatlng,
title: "Hello World!"
});
// To add the marker to the map, call setMap();
marker.setMap(map);
} else {
marker.setPosition(myLatlng);
}
}, 5000);
关于javascript - Google map - 如何在不刷新布局的情况下添加标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29806815/