Created
September 17, 2015 12:03
-
-
Save ParkMinKyu/50fd31a9c813a8df6385 to your computer and use it in GitHub Desktop.
google api 주소 좌표전환 샘플
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
package com.niee.restful.web.controller; | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.net.URL; | |
import java.net.URLEncoder; | |
import javax.servlet.http.HttpServletResponse; | |
import org.springframework.web.bind.annotation.RequestMapping; | |
import org.springframework.web.bind.annotation.RequestMethod; | |
import org.springframework.web.bind.annotation.RequestParam; | |
import org.springframework.web.bind.annotation.RestController; | |
@RestController | |
public class HelloController { | |
@RequestMapping(value = { "/", "hello" }, method = RequestMethod.GET) | |
public void hello(@RequestParam("addr") String addr, HttpServletResponse res) { | |
StringBuilder sb = new StringBuilder(); | |
try { | |
URL ocu = new URL( | |
"http://maps.googleapis.com/maps/api/geocode/xml?language=ko&sensor=false&address=" | |
+ URLEncoder.encode(addr, "UTF-8")); | |
BufferedReader in = new BufferedReader(new InputStreamReader( | |
ocu.openStream())); | |
String line = null; | |
while ((line = in.readLine()) != null) { | |
sb.append(line); | |
} | |
in.close(); | |
res.setContentType("text/xml;charset=UTF-8"); | |
res.getWriter().write(sb.toString()); | |
} catch (IOException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment