Skip to content

Commit

Permalink
좌표 변환 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
kkyh12180 committed Nov 11, 2023
1 parent 0faf6d8 commit e6d18fc
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 17 deletions.
36 changes: 36 additions & 0 deletions api/convertAddress/address2grid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import requests
import os
import json
import sys

def add2gird(address) :
# address = '경기도 성남시 분당구 판교로 264'
url = f'''https://apis.openapi.sk.com/tmap/geo/convertAddress?version=1&searchTypCd=NtoO&reqAdd={address}&reqMulti=S&resCoordType=WGS84GEO'''

headers = {
"accept": "application/json",
"appKey": "e8wHh2tya84M88aReEpXCa5XTQf3xgo01aZG39k5"
}

response = requests.get(url, headers=headers)

if response.status_code == 200 :
json_data = response.text
add_dict = json.loads(json_data)
# print(add_dict)
# 위도 정보
latitude = add_dict['ConvertAdd']['newAddressList']['newAddress'][0]['newLat']
# 경도 정보
longitude = add_dict['ConvertAdd']['newAddressList']['newAddress'][0]['newLon']

result_dict = {}
result_dict['address'] = address
result_dict['lat'] = latitude
result_dict['lon'] = longitude

json_string = json.dumps(result_dict)
print(json_string)

if __name__ == "__main__" :
address = sys.argv[1]
add2gird(address)
29 changes: 17 additions & 12 deletions api/convertAddress/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,27 @@ module.exports = async function (context, req) {
};

async function convertAddressToCoordinates(address) {
const apiUrl = `https://apis.openapi.sk.com/tmap/geo/convertAddress?version=1&searchTypCd=NtoO&reqAdd=${address}&reqMulti=S&resCoordType=WGS84GEO`;
const apiKey = "e8wHh2tya84M88aReEpXCa5XTQf3xgo01aZG39k5";
const call_command = `python ./convertAddress/address2grid.py ${address}`;
// console.log(call_command);

const headers = {
"accept": "application/json",
"content-type": "application/json",
"appKey": apiKey
};
const execSync = require('child_process').execSync;
const resultBuffer = execSync(call_command, { encoding: 'utf-8' });
const result = resultBuffer.toString();

const response = await axios.get(apiUrl, { headers });

if (response.status !== 200) {
throw new Error(`TMap API request failed with status code ${response.status}`);
var jsonData = ""
try {
jsonData = JSON.parse(result);
// console.log(jsonData);
} catch (error) {
console.error('JSON 파싱 오류:', error.message);
}

return JSON.parse(response.data);
context.res.json({
// status: 200, /* Defaults to 200 */
address: jsonData.address,
lon: jsonData.lon,
lan: jsonData.lan
});
}

async function getTransitFare(coordinates) {
Expand Down
4 changes: 2 additions & 2 deletions api/ktx_schedule/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = async function (context, req) {
const time = "120000";

const call_command = `python ./ktx_schedule/ktx_api.py ${dep} ${arr} ${date} ${time}`;
console.log(call_command);
// console.log(call_command);

const execSync = require('child_process').execSync;
const resultBuffer = execSync(call_command, { encoding: 'utf-8' });
Expand All @@ -17,7 +17,7 @@ module.exports = async function (context, req) {
var jsonData = ""
try {
jsonData = JSON.parse(result);
console.log(jsonData);
// console.log(jsonData);
} catch (error) {
console.error('JSON 파싱 오류:', error.message);
}
Expand Down
132 changes: 129 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@azure/static-web-apps-cli": "^0.2.1"
},
"dependencies": {
"axios": "^1.6.1",
"swa": "^0.0.8"
}
}

0 comments on commit e6d18fc

Please sign in to comment.