Created
March 11, 2021 05:00
-
-
Save IngIeoAndSpare/5cffdccb29b5d95f0fb33f2858c7a3f3 to your computer and use it in GitHub Desktop.
geocoding using VWorld
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## url 접속을 위한 실습 | |
import urllib | |
import json | |
import folium | |
geo_url_context = "http://api.vworld.kr/req/address?service=address&request=getcoord&version=2.0" | |
## url 주기 | |
def get_request_url(address, key, address_type="PARCEL") : | |
address = urllib.parse.quote(address) | |
request_url = f"{geo_url_context}&address={address}&&type={address_type}&key={key}" | |
return request_url | |
def request_point(request_url): | |
request = urllib.request.Request(request_url) | |
response = urllib.request.urlopen(request) | |
rescode = response.getcode() | |
if rescode == 200: | |
response_body = response.read() | |
return response_body.decode('utf-8') | |
else : | |
print("error") | |
def get_coordinate_from_request_result(json_text): | |
json_object = json.loads(json_text) | |
result = { | |
'x' : float(json_object['response']['result']['point']['x']), | |
'y' : float(json_object['response']['result']['point']['y']) | |
} | |
return result | |
key = {{API_KEYS}} | |
url = get_request_url("대전 유성구 대학로 245", key, "ROAD") | |
result = request_point(url) | |
point_object = get_coordinate_from_request_result(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment