반응형
네이버 API 사용
def search_map(search_text):
client_id = 'client_id number' #클라이언트 ID값
client_secret = 'client_secret number' #클라이언트 Secret값
encText = urllib.parse.quote(search_text)
url = 'https://naveropenapi.apigw.ntruss.com/map-geocode/v2/geocode?query='+encText
request = urllib.request.Request(url)
request.add_header('X-NCP-APIGW-API-KEY-ID', client_id)
request.add_header('X-NCP-APIGW-API-KEY', client_secret)
response = urllib.request.urlopen(request)
rescode = response.getcode()
if(rescode==200):
response_body = response.read()
return response_body.decode('utf-8')
else:
print("Error Code:" + rescode)
주소 입력
user = search_map("서울특별시 금천구 독산로 53")
print(user)
user = json.loads(user)
user = user['addresses'][0]
print(user)
test = (float(user['x']),float(user['y']))
print(test)
반응형