polyline을 적용했는데 배열 순서대로 그려지질 않고 랜덤으로 그려져서 새로고침을 할 때마다 순서가 바뀝니다 도저히 이유를 찾지 못하겠어서 혹시 답을 얻을 수 있을까 싶어 문의 남깁니다…
var arr = new Array();
<c:forEach items="${list}" var=“list”>
arr.push({
title: “${list.spot_title}”,
address: “${list.spot_address}”
});
</c:forEach>
var positions = arr;
positions.forEach(function(pos, index){
geocoder.addressSearch(positions[index].address, function(result, status) {
if (status === kakao.maps.services.Status.OK) {
var coords = new kakao.maps.LatLng(result[0].y, result[0].x);
var marker = new kakao.maps.Marker({
map: map,
position: coords,
image: markerImage
});
marker.setMap(map);
var infowindow = new kakao.maps.InfoWindow({
content: '<div style="width:150px;text-align:center;padding:6px 0;">' + positions[index].title + '</div>'
});
kakao.maps.event.addListener(marker, 'mouseover', makeOverListener(map, marker, infowindow));
kakao.maps.event.addListener(marker, 'mouseout', makeOutListener(infowindow));
bounds.extend(new kakao.maps.LatLng(coords.Ma, coords.La));
map.setBounds(bounds);
linePath.push(new kakao.maps.LatLng(coords.Ma, coords.La));
console.log(linePath);
var polyline = new kakao.maps.Polyline({
path: linePath,
strokeWeight: 3,
strokeOpacity: 1,
strokeColor: 'red',
strokeStyle: 'solid'
});
polyline.setMap(map);
}
});
});