33
44URL_ADDR = "https://api.vworld.kr/req/address"
55URL_PNU = "https://api.vworld.kr/req/data?service=data&request=GetFeature&attrFilter=pnu:=:{pnu}&data=LP_PA_CBND_BUBUN&key={apikey}"
6- URL_MAP = "https://naveropenapi.apigw.ntruss.com/map-static/v2/raster "
6+ URL_MAP = "https://api.vworld.kr/req/image "
77
88MAPLINK_SEED1 = "https://map.kakao.com/link/search/{addr}"
99MAPLINK_SEED2 = "https://map.kakao.com/link/roadview/{y},{x}"
@@ -71,42 +71,25 @@ def get_mapinfo_from_pnu(apikey, pnu):
7171 return [addr , maplink1 , maplink2 , maplink3 ], [str (x ), str (y )]
7272
7373
74- ###
75- # 로그인 ::: https://www.ncloud.com/product/applicationService/maps
76- # API ::: https://api.ncloud-docs.com/docs/ai-naver-mapsstaticmap-raster
77- ###
78- def get_map_img (c_id , c_sec , epsg ):
79- lon , lat = epsg [0 ], epsg [1 ]
74+ def get_map_img (api_key , epsg , zoom = 18 , width = 1024 , height = 1024 , basemap = "PHOTO_HYBRID" ):
75+ x = epsg [0 ]
76+ y = epsg [1 ]
8077
81- # 좌표 (경도, 위도)
82- headers = {
83- "X-NCP-APIGW-API-KEY-ID" : c_id ,
84- "X-NCP-APIGW-API-KEY" : c_sec ,
78+ zoom = min (max (zoom , 6 ), 18 )
79+
80+ params = {
81+ "service" : "image" ,
82+ "request" : "getmap" ,
83+ "key" : api_key ,
84+ "format" : "png" ,
85+ "basemap" : basemap ,
86+ "center" : f"{ x } ,{ y } " ,
87+ "zoom" : zoom ,
88+ "size" : f"{ width } ,{ height } " ,
89+ "marker" : f"point:{ x } { y } |image:img09"
8590 }
86- # 중심 좌표
87- _center = f"{ lon } ,{ lat } "
88- # 줌 레벨 - 0 ~ 20
89- _level = 16
90- # 가로 세로 크기 (픽셀)
91- _w , _h = 700 , 500
92- # 지도 유형 - basic, traffic, satellite, satellite_base, terrain
93- _maptype = "satellite"
94- # 반환 이미지 형식 - jpg, jpeg, png8, png
95- _format = "png"
96- # 고해상도 디스펠레이 지원을 위한 옵션 - 1, 2
97- _scale = 1
98- # 마커
99- _markers = f"""type:d|size:small|pos:{ lon } { lat } |color:yellow"""
100- # 라벨 언어 설정 - ko, en, ja, zh
101- _lang = "ko"
102- # 대중교통 정보 노출 - Boolean
103- _public_transit = True
104- # 서비스에서 사용할 데이터 버전 파라미터 전달 CDN 캐시 무효화
105- _dataversion = ""
106-
107- # URL
108- url = f"{ URL_MAP } ?center={ _center } &level={ _level } &w={ _w } &h={ _h } &maptype={ _maptype } &format={ _format } &scale={ _scale } &markers={ _markers } &lang={ _lang } &public_transit={ _public_transit } &dataversion={ _dataversion } "
109- res = requests .get (url , headers = headers )
91+
92+ res = requests .get (URL_MAP , params = params )
11093
11194 return res .status_code == 200 , res .content
11295
@@ -115,14 +98,11 @@ def get_map_img(c_id, c_sec, epsg):
11598 apikey = ""
11699 pnu = "4377034032102800000"
117100
118- client_id = ""
119- client_secret = ""
120-
121101 l , b = get_mapinfo_from_pnu (apikey , pnu )
122102 if not b :
123103 print ("error" )
124104 else :
125- iss , pm = get_map_img ( client_id , client_secret , b )
105+ iss , pm = get_static_map ( apikey , b )
126106
127107 print (l , b )
128108 print (iss )
0 commit comments