import requests
Replace YOUR_REST_API_KEY with your actual Kakao API key
REST_API_KEY = “33ea7a29f8e5b1df55df0c002271dae8”
url = “https://apis-navi.kakaomobility.com/v1/origins/directions”
headers = {
“Content-Type”: “application/json”,
“Authorization”: f"KakaoAK {REST_API_KEY}"
}
data = {
“origins”: [
{
“x”: “127.1331694942593”,
“y”: “37.4463137562622”,
“key”: “0”
},
{
“x”: “127.13243772760565”,
“y”: “37.44148514309502”,
“key”: “1”
}
],
“destination”: {
“x”: “127.13243772760565”,
“y”: “37.44148514309502”
},
“radius”: 10000
}
response = requests.post(url, headers=headers, json=data)
print(response.status_code)
print(response.json())
파이썬으로 이렇게 코딩을 해봤는데요,
origin에서 {
“x”: “127.13243772760565”,
“y”: “37.44148514309502”,
“key”: “1”
}
이랑
destination에서
“destination”: {
“x”: “127.13243772760565”,
“y”: “37.44148514309502”
두 x,y가 같아서 실행했을 때 0에 가까운 결과가 나와야한다고 생각했는데
{‘trans_id’: ‘018c48f81dc27d2b961b89cba444146e’, ‘routes’: [{‘result_code’: 0, ‘result_msg’: ‘길찾기 성공’, ‘key’: ‘0’, ‘summary’: {‘distance’: 1022, ‘duration’: 396}}, {‘result_code’: 0, ‘result_msg’: ‘길찾기 성공’, ‘key’: ‘1’, ‘summary’: {‘distance’: 668, ‘duration’: 259}}]}
이런 결과가 나옵니다. 왜 그런건가요?
REST_API_KEY = “33ea7a29f8e5b1df55df0c002271dae8”
url = “https://apis-navi.kakaomobility.com/v1/origins/directions”
headers = {
“Content-Type”: “application/json”,
“Authorization”: f"KakaoAK {REST_API_KEY}"
}
data = {
“origins”: [
{
“x”: “127.1331694942593”,
“y”: “37.4463137562622”,
“key”: “0”
},
{
“x”: “127.13243772760565”,
“y”: “37.44148514309502”,
“key”: “1”
}
],
“destination”: {
“x”: “127.1331694942593”,
“y”: “37.4463137562622”
},
“radius”: 5000
}
response = requests.post(url, headers=headers, json=data)
print(response.status_code)
print(response.json())
아 그리고 반대로 이렇게 하면
{‘trans_id’: ‘018c48f7f6627024bb01f265e6e7dca7’, ‘routes’: [{‘result_code’: 0, ‘result_msg’: ‘길찾기 성공’, ‘key’: ‘0’, ‘summary’: {‘distance’: 1, ‘duration’: 2}}, {‘result_code’: 0, ‘result_msg’: ‘길찾기 성공’, ‘key’: ‘1’, ‘summary’: {‘distance’: 937, ‘duration’: 354}}]}
이렇게 distance가 1로 잘나옵니다…