<p><span style="color: #404040; font-family: 굴림;">package kr.or.kosta;&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">/*&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">&nbsp;*현재 위치&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">&nbsp;*lon:127.1220017&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">&nbsp;* lat:37.4940833&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">&nbsp;*&nbsp;&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">&nbsp;*/&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">import android.app.Activity;&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">import android.content.Context;&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">import android.location.Location;&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">import android.location.LocationListener;&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">import android.location.LocationManager;&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">import android.os.Bundle;&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">import android.widget.TextView;&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">public class GetLocationByLocationListenerActivity extends Activity {&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">&nbsp; &nbsp; /** Called when the activity is first created. */&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">private TextView txtInfo;&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">private LocationManager locationManager;&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">@Override&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">protected void onCreate(Bundle savedInstanceState) {&nbsp; //객체 생성 후 호출, 화면을 구성하는 객체 생성&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">super.onCreate(savedInstanceState);&nbsp; //Activity 로 부터 상속받은 속성을 초기화, 반드시 호출&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">setContentView(R.layout.main);&nbsp; //main.xml (res/main.xml)의 태그를 읽어서 객체 생성&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">txtInfo = (TextView) findViewById(R.id.txtInfo);&nbsp; //id속성이 txtInfo인 객체 리턴&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); //LocationManager 리턴&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">}&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">@Override&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">protected void onResume() {&nbsp; //활성화 직전&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">super.onResume();&nbsp; //반드시 호출, 실제 Activity 활성화단계&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">locationManager.requestLocationUpdates(&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">//LocationManager.GPS_PROVIDER, 1000, 0, locationListener);&nbsp; //위치정보요청 (장치선택, 주기-1/1000sec, 최소이동거리-meter, 응답시콜메소드)&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">LocationManager.NETWORK_PROVIDER, 1000, 0, locationListener);&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">}&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">@Override&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">protected void onPause() {&nbsp; //비활성화 직후, ex)전화가 왔을경우, 홈버튼 클릭스&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">super.onPause();&nbsp; //반드시 호출, 실제 Activity 비활성화단계---&gt;뒤로가면서 본 서비스를 ActivityStack에 저장&nbsp;&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //뒤로가기 버튼 호출시, ActivityStack 에 있는 것을 역순차적으로 꺼내서 실행&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">locationManager.removeUpdates(locationListener);&nbsp; //응답시콜메소드-locationListener 를 더이상 호출하지 않음&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">}&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">private LocationListener locationListener = new LocationListener() {&nbsp; //위치정보응답이 왔을때 호출, 현재 위치정보값이 인자로 존재&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">public void onLocationChanged(Location location) {&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">txtInfo.append("위도: " + location.getLatitude() + "\n");&nbsp; //화면표시&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">txtInfo.append("경도: " + location.getLongitude() + "\n\n");&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">}&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">public void onProviderDisabled(String provider) {}&nbsp; //위치정보값 제공이 불가능할때&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">public void onProviderEnabled(String provider) {}&nbsp; //위치정보값 제공이 가능할때&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">public void onStatusChanged(String provider, int status, Bundle extras) {}&nbsp; //위치제공자 상태가 변화할경우&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">};&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">}</span></p>