var currentLat = 0.0 var currentLon = 0.0 let baseData = { 'title': "", 'content': "", 'firstPostLat': "", 'firstPostLon': "", 'category' : "none", 'hashTags' : "#none", } function onclickWrite(type, keyword, html) { let title_field = document.getElementById('title_field') var hasValues = true if (hasValues) { baseData.title = encodeURIComponent(title_field.value) baseData.content = encodeURIComponent(html) baseData.firstPostLat = encodeURIComponent(currentLat) baseData.firstPostLon = encodeURIComponent(currentLon) } let uploadUrl = getMainPath() + "/blog/post.ajax"; if(confirm(JSON.stringify(baseData) + "\n해당 내용으로\n유저 등록 하실??")) { post(uploadUrl,type,JSON.stringify(baseData),keyword, function (resultData) { alert(resultData) }) } else { } } function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition); } else { x.innerHTML = "Geolocation is not supported by this browser."; } } function showPosition(position) { currentLat = position.coords.latitude currentLon = position.coords.longitude baseData.firstPostLat = encodeURIComponent(currentLat) baseData.firstPostLon = encodeURIComponent(currentLon) document.getElementById('location_field').value = "Lat: " + position.coords.latitude + ", Lon: " + position.coords.longitude; }