일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 프로그래머스 #파이썬 #알고리즘 #코딩테스트
- 재귀
- dp
- 다이나믹프로그래밍
- 프로그래머스
- 자바 #java
- 백준
- 코딩테스트
- 파이썬 #알고리즘 #코딩테스트 #프로그래머스
- 파이썬
- 파이썬 #백준 #알고리즘 #코딩테스트
- react #리액트 #동빈나
- react #리액트 #동빈나 #나동빈 #유튜브강의
- 백트랙킹
- java #자바 #동빈나
- css #웹 #생활코딩
- BFS
- java #자바 #나동빈
- 백준 #파이썬 #알고리즘 #코딩테스트
- Dijkstra
- 다익스트라
- PYTHON
- 프로그래머스 #파이썬 #코딩테스트 #알고리즘
- 알고리즘
- 투포인터
- java #자바 #생활코딩
- css #생활코딩 #웹
- DFS
- 백준 #알고리즘 #파이썬 #코딩테스트
- java #자바
Archives
- Today
- Total
커리까지
자바 응용 프로그램 개발 실전 테크닉 1강 - 구글 맵 연동 본문
728x90
SMALL
public class Execute {
public static void main(String[] args) {
Main main = new Main();
}
}
import javax.swing.JFrame;
public class Main extends JFrame{
public Main() {
setTitle("Google Maps");
setVisible(true);
pack();
}
}
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLEncoder;
import javax.swing.ImageIcon;
public class GoodleAPI {
public void downloadMap(String location){
try {
String imageURL = "https://developers.google.com/maps/api/staticmap?center="
+URLEncoder.encode(location, "UTF-8") + "&zoom=11&size=612x612&scale=2";
URL url = new URL(imageURL);
InputStream is = url.openStream();
OutputStream os = new FileOutputStream(location);
byte[] b = new byte[2048];
int length;
while ((length = is.read(b)) != -1) {
os.write(b,0,length);
}
is.close();
os.close();
}catch(Exception e) {
e.printStackTrace();
}
}
public ImageIcon getMap(String location) {
return new ImageIcon((new ImageIcon(location)).getImage().getScaledInstance(612, 612, java.awt.Image.SCALE_SMOOTH));
}
public void fileDelete(String fileName) {
File f = new File(fileName);
f.delete();
}
}
- URLEncoder.encode
- 인코딩이 다르면 안되니깐 utf-8로 맞춰준다.
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Main extends JFrame{
private GoogleAPI googleAPI = new GoogleAPI();
private String location = "서울";
private JLabel googleMap;
public Main() {
googleAPI.downloadMap(location);
googleMap = new JLabel(googleAPI.getMap(location));
googleAPI.fileDelete(location);
setTitle("Google Maps");
setVisible(true);
pack();
}
}
- 현재 api는 다른 주소로 바꿔서 해야한다. 구글맵에서 따로 api키를 받아서 입력하는 방식으로 변했다.
728x90
LIST
'자바' 카테고리의 다른 글
[생활코딩] JAVA1 - 4.2. 실행 - Java의 동작원리 (0) | 2021.03.23 |
---|---|
생활코딩 4.1. 실행 - HelloWorld (0) | 2021.03.22 |
자바 기초 프로그래밍 강좌 23강 - 객체 지향 기법의 활용 (0) | 2021.03.11 |
자바 기초 프로그래밍 강좌 22강 - Object 클래스 (0) | 2021.03.10 |
자바 기초 프로그래밍 강좌 21강 - 다형성 (0) | 2021.03.09 |
Comments