var centers = [
{latlng: new maps.LatLng(33.4457991, 126.488551)},
{latlng: new maps.LatLng(33.44546106, 126.4887215)},
..... ,
{latlng: new maps.LatLng(33.44510391, 126.4887526)}
]
다음과 같은 수많은 위 경도 값 객체가 있다.
function move() {
centers.forEach(function (center, index) {
setTimeout(function () {
// do whatever
console.log("move!!!");
map.panTo(center.latlng);
map.setCenter(center.latlng);
}, 10 * (index + 1));
})
}
function initialize() {
// map 초기화
mapOpts = {
center: new maps.LatLng(33.52384675, 126.5444758),
zoom: 8,
mapTypeId: 'ROADMAP',
};
map = new maps.Map(document.getElementById('map'), mapOpts);
// map 을 클릭할 때 moveToKT함수를 호출하도록 함. map을 매개변수로 갖는다.
// center 값이 계속 바뀌면서 move함수를 호출해야 한다.
map.onEvent('click', function (event, payload) {
move();
}, map);
}
json.objects.forEach(function(obj, index) {
setTimeout(function(){
// do whatever
}, 5000 * (index + 1));
});
https://stackoverflow.com/questions/37977602/settimeout-not-working-inside-foreach
https://stackoverflow.com/questions/3583724/how-do-i-add-a-delay-in-a-javascript-loop
https://devtalk.kakao.com/t/topic/56194