마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

GPS 주소 textview 로 불러오기

0 추천
아래 소스에서 처리된 주소를

textview 로 불러오는 방법

 

 

 public String getAddress(double latitude, double longitude){

        String address = null;

 

        //위치정보를 활용하기 위한 구글 API 객체

        Geocoder geocoder = new Geocoder(this, Locale.getDefault());

 

        //주소 목록을 담기 위한 HashMap

        List<Address> list = null;

        try{

            list = geocoder.getFromLocation(latitude, longitude, 1);

        } catch(Exception e){

            e.printStackTrace();

        }

        if(list == null){

            Log.e("getAddress", "주소 데이터 얻기 실패");

            return null;

        }

        if(list.size() > 0){

            Address addr = list.get(0);

            address = addr.getCountryName() + " "

                    + addr.getPostalCode() + " "

                    + addr.getLocality() + " "

                    + addr.getThoroughfare() + " "

                    + addr.getFeatureName();

        }

        return address;

    }
익명사용자 님이 2017년 10월 12일 질문

1개의 답변

0 추천

TextView text = (TextView)findVieewById(R.id.textView);

text.setText(getAddress(latitude, longitude);

지나가는심심한개발자 님이 2017년 10월 13일 답변
...