// odaeri/js/readyGeoLocation.js /* // GeoLocation 을 먼저 확보한다. // GEO 좌표/주소 등 정보만을 사전확보한다. // 확보된 좌표와 주소는 sessionStorage 객체에 스트링으로 보관되고, // 오더폼 orderForm 의 히든 밸류로 insert 될 것이다. -- 요금검색 기록이 있든 없든, 단말기 좌표정보를 무조건 받아온다. 실패시 페이지 종료. -- 현 단계에서 위치정보는 클라이언트 사이드 JS 레벨에서만 접근가능... */ // 트리거 펑션 : // geoActionGateWay(); // onLoad 시에 위치정보 확인중 JQM 의 디폴트 로딩 이미지가 노출되는 것을 방지.. // 사용자의 현위치를 확인한다. // 성공시 readyCoords() 펑션 호출 function geoActionGateWay( ) { if(navigator.geolocation) { console.log("geoActionGateWay 펑션 호출"); navigator.geolocation.getCurrentPosition( readyCoords, onError); // 각 좌표계의 좌표를 확보한다. } } function onError() { console.log("Failed to get navigator.geolocation"); // 구글크롬일 때, https 로 리다이렉션 & 프로세스 처리...... // 이건 여기서 할 일이 아니라, preHeader 에서 해줘야 하는게 맞겠다. } // epsg4326, epsg3857 양 좌표계의 좌표값을 확보한다. // 브라우저 내장함수 getCurrentPosition() 의 콜백함수로 호출된다. function readyCoords(location) { console.log("readyCoords 펑션 호출"); ajaxLoadingScreenOn(); latiVal= location.coords.latitude; longVal= location.coords.longitude; console.log("X축: "+longVal); console.log("Y축: "+latiVal); // 2. 변환좌표계를 미리 확보해해두고, coord4326 = [ longVal , latiVal ]; //coord3857 = ol.proj.transform([longVal, latiVal], 'EPSG:4326', 'EPSG:3857'); // 3857 좌표 //console.log("변환좌표계 3857: "+coord3857[0]+", "+coord3857[1]); sessionStorage.setItem('geoLocation4326X', longVal ); // sessionStorage 로 보관된다. sessionStorage.setItem('geoLocation4326Y', latiVal ); // sessionStorage 로 보관된다. sessionStorage.setItem('geoLocation4326', JSON.stringify(coord4326) ); // sessionStorage 로 보관된다. //sessionStorage.setItem('geoLocation3857', JSON.stringify(coord3857) ); // sessionStorage 로 보관된다. queryCoordToAddr(coord4326, callBackFunc); // 3857 좌표계로부터 주소를 확보한다. } // 4326 좌표를 주소로 바꿔달라는 요청을 내부 php /ajax/tryToGetAddr.php 에 전달하고, // 결과값 Json 을 받아온다. function queryCoordToAddr(coord4326, callBackFunc) { //sessionStorage.clear(); //localStorage.clear(); //console.log("queryCoordToAddr 펑션 호출"); // 3. 국가지도 API 에 좌표의 주소값을 쿼리하는 php 스크립트를 Ajax 호출한다. // 4. 리다이렉션 될 $keyId 가 필요하다. 이 값은 tryToGetAddr.php 스크립트에서 세션밸류로 처리 불가... //var paramStr='long='+coord4326[0]+'&lat='+coord4326[1]+"&x3857="+coord3857[0]+"&y3857="+coord3857[1]; //$.getJSON( "/ajax/tryToGetAddr.php?"+paramStr+"&callback=?", function( jsonObj ) { var paramStr='y='+coord4326[1]+'&x='+coord4326[0]; console.log( "paramStr : " +paramStr ); $.getJSON( "/ajax/geoCoder.php?"+paramStr+"&callback=?", function( jsonObj ) { // str = JSON.stringify(json, null, 4); // (Optional) beautiful indented output. // console.log( "resultAddr:"+ JSON.parse(str.resultAddr) ); // console.log( "geoId: "+ jsonObj.geoId ); // console.log( "resultAddr: "+ jsonObj.resultAddr ); // 주소 받아오기에 성공한 경우에만... if( typeof jsonObj==="object" ) { sessionStorage.setItem('deptAddressGeoId', jsonObj.geoId); // GeoId //sessionStorage.setItem('deptAddressKeywordId', jsonObj.resultKeyId); // KeywordId sessionStorage.setItem('deptAddressFullString', jsonObj.resultAddr); // 풀어드레스 : sessionStorage 로 보관된다. $("#deptAddrInputField, #deptAddrOutputField").val(jsonObj.resultAddr); $("#deptAddrOutputField").text(jsonObj.resultAddr); console.log("Address: "+jsonObj.resultAddr); console.log("GeoId: "+jsonObj.geoId); console.log("callBackFunc: "+callBackFunc); // 콜백 펑션 호출 if(callBackFunc) window[callBackFunc](); else ajaxLoadingScreenOff(); } else { alert("죄송합니다. 주소를 읽어오기에 실패하였습니다."); } }); } // Geo Data 확보가 완료된 이후, input fields 와 출력 Text 를 업데이트 해준다.. // 랜딩페이지의 keyId 가 새로 확보된 조소의 keyId 와 일치하지 않을 때, 새로운 keyId 로 이동시켜준다. function geoActionCallback() { console.log("geoActionCallback 펑션 호출.. "); var newGeoId = sessionStorage.getItem('deptAddressGeoId'); var newCoordX = sessionStorage.getItem('geoLocation4326X'); var newCoordY = sessionStorage.getItem('geoLocation4326Y'); var newFullAddr = sessionStorage.getItem('deptAddressFullString'); var newKeyId = sessionStorage.getItem('deptAddressKeywordId'); var newURL = ""; console.log("newGeoId: "+newGeoId); console.log("newFullAddr: "+newFullAddr); // input field 밸류 변경 if(newGeoId) { $(".deptGeoId").val(newGeoId); $("#deptGeoId").val(newGeoId); $("#deptFullAddr").val(newFullAddr); $("#deptCoord4326X").val(newCoordX); $("#deptCoord4326Y").val(newCoordY); } // 출력 변경 $(".deptFullAddress").text(newFullAddr); // 팝업 Off $("#deptPointDialogDiv").slideUp(); // 필요할 경우 페이지 이동 //console.log("keyId:"+keyId); //console.log("newKeyId:"+newKeyId); //console.log("newURL:"+ location.pathname+"?keyId="+newKeyId ); if( location.pathname.match(/land/) && keyId != newKeyId) { newURL = location.pathname+"?keyId="+newKeyId; //if(window.confirm("현재 계신 지역의 페이지로 이동합니다.")) document.location.href= newURL; } else if( keyId=="" && newKeyId ) { newURL = "/land/index.html?keyId="+newKeyId; //if(window.confirm("현재 계신 지역의 페이지로 이동합니다.")) document.location.href= newURL; } // console.log("deptFullAddress: "+fullAddr); ajaxLoadingScreenOff(); }