지도 객체를 생성 프로세스를 임의의 함수 안에 넣어 구현하였습니다.
function map_view(){
… 맵생성 프로세스…
}
아래와 같이…
목적은 지도 상에 마커를 페이지 새로고침 없이 생성하기 위함 입니다.
주소정보를 배열변수(listData)에 넣어 배열변수 값이 변동될 때마다 페이지 새로고침을 하지 않고 동적으로 맵을 자동갱신? 하려는 목적입니다.
그리고 배열변수가 변동처리 되는 스크립트함수 안에서 map_view() 함수를 호출해 보고 있습니다만…
결과가 콜백될 때 status 값이 ZERO_RESULT 가 출력이 됩니다.
혹… 배열 데이터는 자체적으로 다시 검증을 해보겠는데… 별도의 맵 호출 함수를 써서 다른 함수에서 맵함수를 호출해서 쓸 수는 없는지 궁금하여 문의드려 봅니다.
… 이하 소스샘플…
var map = new daum.maps.Map(mapContainer, mapOption);
var listData = [];
function map_view(){
//alert(listData.toString());
map = new daum.maps.Map(mapContainer, mapOption);
// 주소-좌표 변환 객체를 생성합니다
var geocoder = new daum.maps.services.Geocoder();
listData.forEach(function(addr, index) {
geocoder.addressSearch(addr, function(result, status) {
if (status === daum.maps.services.Status.OK) {
var coords = new daum.maps.LatLng(result[0].y, result[0].x);
var marker = new daum.maps.Marker({
map: map,
position: coords
});
var infowindow = new daum.maps.InfoWindow({
content: '<div style="width:150px;text-align:center;padding:6px 0;">' + listData[index] + '</div>',
disableAutoPan: true
});
infowindow.open(map, marker);
}
});
});
}