Skip to content

Instantly share code, notes, and snippets.

@ParkMinKyu
Created September 17, 2015 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ParkMinKyu/50fd31a9c813a8df6385 to your computer and use it in GitHub Desktop.
Save ParkMinKyu/50fd31a9c813a8df6385 to your computer and use it in GitHub Desktop.
google api 주소 좌표전환 샘플
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