샘플에 있는 키워드로 장소검색하고 목록표출하기에서

http://apis.map.daum.net/web/sample/keywordList/
이 예제에서

각 검색결과에 따라 마우스 오버시
경도 위도값을 표현해주기 위하여

displayPlaces 함수부분에

(function(marker, title,latlng) {
daum.maps.event.addListener(marker, ‘mouseover’, function() {
displayInfowindow(marker, title,latlng);
});

     daum.maps.event.addListener(marker, 'mouseout', function() {
         infowindow.close();
     });

     daum.maps.event.addListener(marker, 'click', function() {
	      
	      //infoCustom.setMap(map);
	      createInfoButton(latlng.getLat(),latlng.getLng());		      
	});
     
     
     itemEl.onmouseover =  function () {
         displayInfowindow(marker, title);
     };

     itemEl.onmouseout =  function () {
         infowindow.close();
     };
 })(marker, places[i].place_name,placePosition);

로 바꾸고
function displayInfowindow(marker, title,latlng) {
// var content = ‘

’ + title + ‘
’;
var content = ‘
’ + title + ‘
’+
’ 경도=’+latlng.getLat()+‘위도=’+latlng.getLng()+’
’;

infowindow.setContent(content);
infowindow.open(map, marker);
}
function createInfoButton(x,y){
document.getElementById(“addBtn”).innerHTML="<input type=‘button’ value=‘세부정보2’ id=‘detail2’"+
“onclick=‘detail(x, y)’/>”;
}

라는 함수기능을 추가해주었습니다. 그런데 검색결과에서 위도가 제대로 표시되지 않는 부분도 있던데 잘못 표현했기때문에 안되는건가요 아니면 예제에서 가져오는 배열에 위도가 담아지지 않아서 나오는 에러인가요..?

그리고 온클릭 이벤트시에 하단에 버튼을 생성하도록 구현했는데
버튼클릭시 alert(경도, 위도)가 뜨도록 하려했으나
정상작동되지않고 외부 html에서 작동되는거같은데… 이부분은 외그런건ㄱ아ㅛ

음… 제가 개발자는 아니라 정확한 답변이 될 지는 모르겠지만,
말씀하신 “검색결과에 따라 마우스 오버시 경도 위도값을 표현” 만을 위해서는

예제 코드에서

    (function(marker, title) {
        daum.maps.event.addListener(marker, 'mouseover', function() {
            displayInfowindow(marker, title);
        });

        daum.maps.event.addListener(marker, 'mouseout', function() {
            infowindow.close();
        });

        itemEl.onmouseover =  function () {
            displayInfowindow(marker, title);
        };

        itemEl.onmouseout =  function () {
            infowindow.close();
        };
    })(marker, places[i].place_name);

places[i].place_name
이것만 가령 places[i].x + ", " + places[i].y

요걸로 바꿔보면 원하시는 결과형태일 듯한데… 원하시는 건 다른 형태일까요?

일단 Latitude는 위도 => 평면직교좌표계에서 y값으로 생각해야하며
일단 Longitude는 경도 => 평면직교좌표계에서 x값에 대응됩니다.

그리고 createInfoButton 내부 구현을 보면 버튼에 이벤트를 거는 방식이 잘못되었습니다.
detail이 어떤 함수인지는 모르겠으나
그냥 문자열로 x, y를 넘겨버리면 HTML에서 그것을 자바스크립 함수에서 받은 파라메터 x, y로 해석해주지 않습니다. 제대로 동작하지 않아요.

예제로 제공해 드리는 코드는 확장성을 크게 고려하지 않았습니다.
때문에 기능을 추가하기 위해 그대로 사용하면 비효율적이거나 동작하지 않는 경우가 많습니다.
이는 직접 코드를 참고해 구조를 변경하거나 응용하여 사용해 주셔야 합니다.

1개의 좋아요