티스토리 뷰


두개를 추가해야 한다.


javascript


여기서 addr은 한글이 들어가면 된다.  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function geoCoding(addr) {
      $.ajax({
        url:"/ajax/geoCoding.do" // geoCoding호출
        ,type:"post"
        ,data: {addr : addr} // 요청변수설정
        ,dataType:"text"
            ,success: function(data) {
                    var map = data.split('&');
                  var map_x = map[0];
                  var map_y = map[1];
          },
          error:function(request,status,error){
            console.log("code:"+request.status+"\n"+"error:"+error);
          }
      });
}
 
cs




Java

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
   ////////////  주소API
    @RequestMapping(value="/ajax/geoCoding.do")
    public void geoCoding(HttpServletRequest req, HttpServletResponse response) throws Exception{
      String location = req.getParameter("addr");
                        
      Geocoder geocoder = new Geocoder();
      // setAddress : 변환하려는 주소 (경기도 성남시 분당구 등)
      // setLanguate : 인코딩 설정
      GeocoderRequest geocoderRequest = new GeocoderRequestBuilder().setAddress(location).setLanguage("ko").getGeocoderRequest();
      GeocodeResponse geocoderResponse;
      geocoderResponse = geocoder.geocode(geocoderRequest);
            if (geocoderResponse.getStatus() == GeocoderStatus.OK & !geocoderResponse.getResults().isEmpty()) {
                  GeocoderResult geocoderResult=geocoderResponse.getResults().iterator().next();
                  LatLng latitudeLongitude = geocoderResult.getGeometry().getLocation();
                                           
                  Float[] coords = new Float[2];
                  coords[0= latitudeLongitude.getLat().floatValue();
                  coords[1= latitudeLongitude.getLng().floatValue();
                  String coordStr = Float.toString(coords[0])+"&"+Float.toString(coords[1]);
                  
                  response.setCharacterEncoding("UTF-8");
              response.setContentType("text/xml");
              response.getWriter().write(coordStr); // 응답결과반환
            }
    }
 
 
 
cs




'JAVA' 카테고리의 다른 글

파일 업로드  (0) 2017.07.21
float형을 string으로  (0) 2017.07.21
네이버 메일 발송 테스트  (0) 2017.07.21
메일 발송 / 지메일 gmail  (0) 2017.07.21
list를 json으로 변경  (0) 2017.07.21
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/03   »
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
글 보관함