FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
excel_pdf/JavaTPCProject/src/NaverMap.java at master · TypeP/excel_pdf · GitHub
TypeP
excel_pdf
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
excel_pdf
/
JavaTPCProject
/
src
/
NaverMap.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
137 lines (110 loc) · 4.14 KB
Breadcrumbs
excel_pdf
/
JavaTPCProject
/
src
/
NaverMap.java
Copy path
File metadata and controls
137 lines (110 loc) · 4.14 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import
java
.
awt
.
event
.
ActionEvent
;
import
java
.
awt
.
event
.
ActionListener
;
import
java
.
io
.
BufferedReader
;
import
java
.
io
.
File
;
import
java
.
io
.
FileOutputStream
;
import
java
.
io
.
InputStream
;
import
java
.
io
.
InputStreamReader
;
import
java
.
io
.
OutputStream
;
import
java
.
net
.
HttpURLConnection
;
import
java
.
net
.
URL
;
import
java
.
net
.
URLEncoder
;
import
java
.
util
.
Date
;
import
javax
.
swing
.
ImageIcon
;
import
org
.
json
.
JSONArray
;
import
org
.
json
.
JSONObject
;
import
org
.
json
.
JSONTokener
;
import
kr
.
inflearn
.
AddressVO
;
public
class
NaverMap
implements
ActionListener
{
Project01_F
naverMap
;
public
NaverMap
(
Project01_F
naverMap
) {
this
.
naverMap
=
naverMap
;
}
@
Override
public
void
actionPerformed
(
ActionEvent
e
) {
String
clientId
=
"8c4fr929n7"
;
String
clientSecret
=
"DXIv7Sj1vTm2vmVKFal4pqdb87zcznpZ4fWf2uga"
;
AddressVO
vo
=
null
;
try
{
String
address
=
naverMap
.
address
.
getText
();
String
addr
=
URLEncoder
.
encode
(
address
,
"UTF-8"
);
String
apiUrl
=
"https://naveropenapi.apigw.ntruss.com/map-geocode/v2/geocode?query="
+
addr
;
URL
url
=
new
URL
(
apiUrl
);
HttpURLConnection
con
=(
HttpURLConnection
)
url
.
openConnection
();
con
.
setRequestMethod
(
"GET"
);
con
.
setRequestProperty
(
"X-NCP-APIGW-API-KEY-ID"
,
clientId
);
con
.
setRequestProperty
(
"X-NCP-APIGW-API-KEY"
,
clientSecret
);
int
responseCode
=
con
.
getResponseCode
();
BufferedReader
br
;
if
(
responseCode
==
200
) {
br
=
new
BufferedReader
(
new
InputStreamReader
(
con
.
getInputStream
(),
"UTF-8"
));
}
else
{
br
=
new
BufferedReader
(
new
InputStreamReader
(
con
.
getErrorStream
()));
}
String
inputLine
;
StringBuffer
response
=
new
StringBuffer
();
//JSON
while
((
inputLine
=
br
.
readLine
())!=
null
) {
response
.
append
(
inputLine
);
}
br
.
close
();
JSONTokener
tokener
=
new
JSONTokener
(
response
.
toString
());
JSONObject
object
=
new
JSONObject
(
tokener
);
System
.
out
.
println
(
object
.
toString
());
JSONArray
arr
=
object
.
getJSONArray
(
"addresses"
);
for
(
int
i
=
0
;
i
<
arr
.
length
();
i
++) {
JSONObject
temp
=(
JSONObject
)
arr
.
get
(
i
);
//addresVO객체에 주소 정보를 저장
vo
=
new
AddressVO
();
vo
.
setRoadAddress
((
String
)
temp
.
getString
(
"roadAddress"
));
vo
.
setJibunAddress
((
String
)
temp
.
getString
(
"jibunAddress"
));
vo
.
setX
((
String
)
temp
.
getString
(
"x"
));
vo
.
setY
((
String
)
temp
.
getString
(
"y"
));
System
.
out
.
println
(
vo
);
}
map_service
(
vo
);
}
catch
(
Exception
err
) {
System
.
out
.
println
(
err
);
}
}
public
void
map_service
(
AddressVO
vo
) {
String
URL_STATICMAP
=
"https://naveropenapi.apigw.ntruss.com/map-static/v2/raster?"
;
try
{
String
pos
=
URLEncoder
.
encode
(
vo
.
getX
() +
" "
+
vo
.
getY
(),
"UTF-8"
);
String
url
=
URL_STATICMAP
;
url
+=
"center"
+
vo
.
getX
()+
","
+
vo
.
getY
();
url
+=
"&level = 16&w=700&h=500"
;
url
+=
"&markers=type:t|size:mid|pos:"
+
pos
+
"|label:"
+
URLEncoder
.
encode
(
vo
.
getRoadAddress
(),
"UTF-8"
);
URL
u
=
new
URL
(
url
);
HttpURLConnection
con
= (
HttpURLConnection
)
u
.
openConnection
();
con
.
setRequestMethod
(
"GET"
);
con
.
setRequestProperty
(
"X-NCP-APIGW-API-KEY-ID"
,
"8c4fr929n7"
);
con
.
setRequestProperty
(
"X-NCP-APIGW-API-KEY"
,
"DXIv7Sj1vTm2vmVKFal4pqdb87zcznpZ4fWf2uga"
);
int
responseCode
=
con
.
getResponseCode
();
BufferedReader
br
;
if
(
responseCode
==
200
) {
InputStream
is
=
con
.
getInputStream
();
int
read
=
0
;
byte
[]
bytes
=
new
byte
[
1024
];
//랜덤한 이름으로 파일 생성
String
tempname
=
Long
.
valueOf
(
new
Date
().
getTime
()).
toString
();
File
f
=
new
File
(
tempname
+
".jpg"
);
f
.
createNewFile
();
OutputStream
outputStream
=
new
FileOutputStream
(
f
);
while
((
read
=
is
.
read
(
bytes
))!=-
1
) {
outputStream
.
write
(
bytes
,
0
,
read
);
}
is
.
close
();
ImageIcon
img
=
new
ImageIcon
(
f
.
getName
());
naverMap
.
imageLabel
.
setIcon
(
img
);
naverMap
.
resAddress
.
setText
(
vo
.
getRoadAddress
());
naverMap
.
jibunAddress
.
setText
(
vo
.
getJibunAddress
());
naverMap
.
resX
.
setText
(
vo
.
getX
());
naverMap
.
resY
.
setText
(
vo
.
getY
());
}
else
{
//에러 발생
System
.
out
.
println
(
responseCode
);
}
}
catch
(
Exception
e
) {
System
.
out
.
println
(
e
);
}
}
}
Back
|
FazBrowse Home
|
New Git URL